Skip to content

FactsDb and performance improvments#9

Merged
techt3 merged 7 commits into
masterfrom
improveachvments
Mar 14, 2026
Merged

FactsDb and performance improvments#9
techt3 merged 7 commits into
masterfrom
improveachvments

Conversation

@techt3
Copy link
Copy Markdown
Owner

@techt3 techt3 commented Mar 10, 2026

  • facts db
  • performance improvments

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/factdb with 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 --pprof profiling 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 thread internal/gui/map.html Outdated
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 thread internal/factdb/factdb.go
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 thread internal/factdb/factdb.go
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."
],
Comment thread internal/factdb/seed_facts.json Outdated
"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 thread internal/gui/app.go
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 thread internal/gui/app.go Outdated
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 thread internal/gui/map.html Outdated
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) {
@techt3 techt3 marked this pull request as ready for review March 14, 2026 12:58
@techt3 techt3 merged commit 633c7ec into master Mar 14, 2026
9 checks passed
@techt3 techt3 deleted the improveachvments branch March 14, 2026 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants