Address code review: add debounce constant and thread-safety comment

Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/9bfe91f2-8ed7-4d2c-bb2e-4ed3dfd3a16c

Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-04-02 00:01:01 +00:00 committed by GitHub
parent a8f4cf9631
commit b6d46ade94
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 2 deletions

View file

@ -45,6 +45,7 @@ class Router: ObservableObject {
// MARK: Node Object ID Cache
/// In-memory cache mapping node numbers to their Core Data `NSManagedObjectID` for O(1) lookups.
/// Thread-safe by virtue of Router's @MainActor isolation all access is on the main thread.
private var nodeObjectIDCache: [Int64: NSManagedObjectID] = [:]
/// Updates the node cache from a set of fetched nodes. Call this when the node list changes.

View file

@ -11,6 +11,9 @@ import CoreData
import Foundation
struct NodeList: View {
/// Debounce delay for node selection changes (100ms)
private static let nodeSelectionDebounceNs: UInt64 = 100_000_000
@Environment(\.managedObjectContext) var context
@EnvironmentObject var accessoryManager: AccessoryManager
@StateObject var router: Router
@ -125,11 +128,11 @@ struct NodeList: View {
}
}
.onChange(of: router.nodeListSelectedNodeNum) { _, newNum in
// Debounce rapid route changes only process the last selection after 100ms
// Debounce rapid route changes only process the last selection after a short delay
nodeSelectionTask?.cancel()
nodeSelectionTask = Task {
do {
try await Task.sleep(nanoseconds: 100_000_000)
try await Task.sleep(nanoseconds: Self.nodeSelectionDebounceNs)
} catch {
return // Cancelled by a newer selection
}