FactsDb and performance improvments#9
Merged
Merged
Conversation
Owner
techt3
commented
Mar 10, 2026
- facts db
- performance improvments
There was a problem hiding this comment.
Pull request overview
Adds a new embedded “Did you know?” fact database and UI surfacing for facts/challenges, alongside several performance-oriented optimizations in map rendering/encoding and some operational tooling tweaks.
Changes:
- Introduces
internal/factdbwith an embedded JSON seed dataset and new HTTP endpoints to serve facts and challenge hints. - Optimizes map generation by caching rasterized country spans and the ocean background, and reduces map PNG encoding work via a “dirty” gate and buffer reuse.
- Updates non-Windows tray icon handling for macOS template icons, and adds an optional
--pprofprofiling server.
Reviewed changes
Copilot reviewed 6 out of 8 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/resources/resources.go | Adds ocean background caching and country span caching to reduce repeated rasterization/expensive per-frame computations. |
| internal/gui/app.go | Wires in FactDB, adds fact/challenge HTTP endpoints, and changes map encoding behavior via map-dirty gating/buffer reuse. |
| internal/gui/map.html | Adds “Did you know?” toast scheduling and a “Research Challenge” banner/poller. |
| internal/gui/tray_icon_unix.go | Adds template tray icon generation and uses template icon API for macOS menu bar rendering. |
| internal/factdb/factdb.go | New embedded fact database with random fact selection API. |
| internal/factdb/seed_facts.json | Adds seed dataset for country/city facts. |
| cmd/iptw/main.go | Adds optional pprof server startup behind a CLI flag. |
| .gitignore | Ignores __debug_bin* artifacts. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+132
to
+166
| .fact-box { | ||
| background: linear-gradient(135deg, rgba(241, 196, 15, 0.15), rgba(230, 126, 34, 0.12)); | ||
| border: 1px solid rgba(241, 196, 15, 0.35); | ||
| color: var(--text-primary); | ||
| padding: 14px 16px; | ||
| border-radius: 14px; | ||
| margin-top: 8px; | ||
| display: none; | ||
| } | ||
|
|
||
| .fact-box.visible { | ||
| display: block; | ||
| } | ||
|
|
||
| .fact-box-label { | ||
| font-size: 0.65rem; | ||
| opacity: 0.6; | ||
| text-transform: uppercase; | ||
| letter-spacing: 1px; | ||
| margin-bottom: 6px; | ||
| } | ||
|
|
||
| .fact-place { | ||
| font-size: 0.75rem; | ||
| font-weight: 600; | ||
| color: #d68910; | ||
| margin-bottom: 4px; | ||
| } | ||
|
|
||
| .fact-text { | ||
| font-size: 0.82rem; | ||
| line-height: 1.45; | ||
| color: var(--text-primary); | ||
| } | ||
|
|
Comment on lines
+113
to
+119
| func (db *DB) pick(m map[string][]string, key string) (string, bool) { | ||
| facts, ok := m[key] | ||
| if !ok || len(facts) == 0 { | ||
| return "", false | ||
| } | ||
| return facts[db.rng.Intn(len(facts))], true | ||
| } |
Comment on lines
+76
to
+95
| // GetFact returns a random interesting fact for the given country and, | ||
| // optionally, city. The lookup order is: city → region → country. | ||
| // Returns a zero Fact{} if no entry is found. | ||
| func (db *DB) GetFact(country, city string) Fact { | ||
| db.mu.RLock() | ||
| defer db.mu.RUnlock() | ||
|
|
||
| if city != "" { | ||
| if f, ok := db.pick(db.data.Cities, city); ok { | ||
| return Fact{Text: f, Level: "city", Place: city} | ||
| } | ||
| } | ||
| if country != "" { | ||
| if f, ok := db.pick(db.data.Regions, country); ok { | ||
| return Fact{Text: f, Level: "region", Place: country} | ||
| } | ||
| if f, ok := db.pick(db.data.Countries, country); ok { | ||
| return Fact{Text: f, Level: "country", Place: country} | ||
| } | ||
| } |
Comment on lines
+839
to
+842
| "Mumbai": [ | ||
| "Mumbai's Dharavi — often called Asia's largest slum — has an internal economy estimated at over $1 billion per year, with cottage industries producing leather goods and textiles exported internationally.", | ||
| "The Mumbai dabbawalas — tiffin box delivery workers — deliver roughly 200,000 home-cooked lunches daily using a colour-coded sorting system so efficient that Harvard Business School studied it as a logistics case." | ||
| ], |
| "Beijing's Forbidden City has 9,999 rooms — deliberately one short of the mythological 10,000 rooms of heaven, which were thought to be the exclusive domain of divine beings.", | ||
| "The Beijing–Shanghai high-speed railway covers 1,318 km in under 5 hours — the same distance as London to Casablanca — at speeds of up to 350 km/h." | ||
| ], | ||
| "Mumbai": [ |
Comment on lines
+1005
to
+1014
| // Only re-encode and re-save when something actually changed. | ||
| a.mapDirtyMu.Lock() | ||
| dirty := a.mapDirty | ||
| a.mapDirty = false | ||
| a.mapDirtyMu.Unlock() | ||
|
|
||
| if !dirty { | ||
| return nil | ||
| } | ||
|
|
Comment on lines
+741
to
+746
| Target string `json:"target,omitempty"` | ||
| Fact factdb.Fact `json:"fact,omitempty"` | ||
| } | ||
|
|
||
| if target == "" || hitSinceSet || time.Since(setAt) < time.Minute { | ||
| if err := json.NewEncoder(w).Encode(hintResponse{Active: false}); err != nil { |
Comment on lines
+890
to
+898
| if (data.active && data.fact && data.fact.text && _challengeDismissedFor !== data.target) { | ||
| document.getElementById('challenge-country').textContent = | ||
| 'Can you verify this about ' + data.target + '?'; | ||
| document.getElementById('challenge-fact').textContent = data.fact.text; | ||
| banner.style.display = 'block'; | ||
| } else if (!data.active) { | ||
| banner.style.display = 'none'; | ||
| // Reset dismissal when target changes | ||
| if (_challengeDismissedFor && _challengeDismissedFor !== data.target) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.