Location notes: fix performance and UI issues (#774)

* Location notes: fix performance and UI issues

Performance fixes:
- Add Set-based duplicate detection (O(1) vs O(n) lookup)
- Eliminates lag when receiving 200+ notes during EOSE

Correctness fixes:
- Fix optimistic echo timestamp to match signed event timestamp
- Add echo IDs to noteIDs set for consistency

UI improvements:
- Remove duplicate "loading recent notes" text in header
- Simplify toolbar icon color logic for immediate green indication
- Icon now reliably turns green when notes exist in geohash

Tests: All 3 LocationNotes tests passing

* Location notes: add remaining robustness fixes

Additional improvements:
- Align counter/manager limits to 200 (prevents showing count higher than displayable)
- Set loading state before clearing notes to eliminate UI flicker on geohash change
- Add geohash validation for building-level precision (8 valid base32 chars)
- Add defensive 500-note memory cap with automatic trimming
- Clear stale notesGeohash state on sheet dismiss

Tests:
- Fix test geohashes to use valid base32 characters
- All 3 LocationNotes tests passing

---------

Co-authored-by: jack <jackjackbits@users.noreply.github.com>
This commit is contained in:
jack
2025-10-07 12:36:54 +02:00
committed by GitHub
co-authored by jack
parent c583949031
commit 0f23ed0a99
6 changed files with 63 additions and 18 deletions
+6 -6
View File
@@ -16,7 +16,7 @@ final class LocationNotesManagerTests: XCTestCase {
// now: { Date() }
// )
//
// let manager = LocationNotesManager(geohash: "abcd1234", dependencies: deps)
// let manager = LocationNotesManager(geohash: "u4pruydq", dependencies: deps)
//
// XCTAssertFalse(subscribeCalled)
// XCTAssertEqual(manager.state, .noRelays)
@@ -66,7 +66,7 @@ final class LocationNotesManagerTests: XCTestCase {
now: { Date() }
)
let manager = LocationNotesManager(geohash: "abcd1234", dependencies: deps)
let manager = LocationNotesManager(geohash: "u4pruydq", dependencies: deps)
XCTAssertEqual(relaysCaptured, ["wss://relay.one"])
XCTAssertEqual(manager.state, .loading)
@@ -74,7 +74,7 @@ final class LocationNotesManagerTests: XCTestCase {
pubkey: "pub",
createdAt: Date(),
kind: .textNote,
tags: [["g", "abcd1234"]],
tags: [["g", "u4pruydq"]],
content: "hi"
)
event.id = "event1"
@@ -102,7 +102,7 @@ final class LocationNotesCounterTests: XCTestCase {
)
let counter = LocationNotesCounter(testDependencies: deps)
counter.subscribe(geohash: "abcdefgh")
counter.subscribe(geohash: "u4pruydq")
XCTAssertFalse(subscribeCalled)
XCTAssertFalse(counter.relayAvailable)
@@ -126,13 +126,13 @@ final class LocationNotesCounterTests: XCTestCase {
)
let counter = LocationNotesCounter(testDependencies: deps)
counter.subscribe(geohash: "abcdefgh")
counter.subscribe(geohash: "u4pruydq")
var first = NostrEvent(
pubkey: "pub",
createdAt: Date(),
kind: .textNote,
tags: [["g", "abcdefgh"]],
tags: [["g", "u4pruydq"]],
content: "a"
)
first.id = "eventA"