Skip to content

Speed up devices list by using local cache for lastUsedTime#29277

Merged
chrisnojima merged 19 commits into
nojima/HOTPOT-next-670-clean-2from
nojima/HOTPOT-faster-devices
Jun 3, 2026
Merged

Speed up devices list by using local cache for lastUsedTime#29277
chrisnojima merged 19 commits into
nojima/HOTPOT-next-670-clean-2from
nojima/HOTPOT-faster-devices

Conversation

@chrisnojima
Copy link
Copy Markdown
Contributor

DeviceHistoryList was calling SyncSecretsForce on every load, triggering a blocking network request to key/fetch_private that took 0.8–4s.

Now reads lastUsedTime from local LevelDB cache (sub-millisecond), with a background goroutine that force-syncs after the response is returned. When the background sync completes, a keyfamilyChanged notification fires so the devices screen auto-refreshes with fresh data — no user action needed.

DeviceHistoryList was calling SyncSecretsForce on every load, triggering
a blocking network request to key/fetch_private that took 0.8–4s.

Now reads lastUsedTime from local LevelDB cache (sub-millisecond), with
a background goroutine that force-syncs after the response is returned.
When the background sync completes, a keyfamilyChanged notification fires
so the devices screen auto-refreshes with fresh data — no user action needed.

This comment was marked as outdated.

- Fix comment in device_history.go: cache fallback is "out-of-date" not "expired"
- Reset lastDeviceSync on background sync failure so next UI refresh retries immediately instead of waiting out the TTL

This comment was marked as outdated.

- device-page.tsx: show "Last used unknown" in timeline when lastUsed is
  missing (non-revoked device), matching list row behavior
- device.go: call NotifyRouter.HandleKeyfamilyChanged directly instead of
  KeyfamilyChanged to avoid unnecessary BustLocalUserCache + HandleUserChanged
  on background sync completion

This comment was marked as outdated.

…rify comment

- Filter keyfamilyChanged listener to current user's uid to avoid
  unnecessary DeviceHistoryList RPCs when other users' caches bust
- Use mctx.ActiveDevice().UID() in backgroundSyncDevices instead of
  h.G().Env.GetUID() for correct/robust uid source
- Fix misleading "empty or out-of-date" comment in getLastUsedTimes;
  forced sync only triggers on empty cache (zero devices)
Comment thread go/service/device.go Outdated
Comment thread go/service/device.go Outdated
Comment thread go/service/device.go Outdated
@zoom-ua
Copy link
Copy Markdown
Contributor

zoom-ua commented Jun 3, 2026

should get a green CI here

Comment thread go/service/device.go Outdated
Comment thread shared/constants/init/shared.tsx Outdated
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

Copilot reviewed 17 out of 18 changed files in this pull request and generated 2 comments.

Comment thread go/engine/device_history.go Outdated
Comment thread go/service/device.go
chrisnojima and others added 5 commits June 3, 2026 10:06
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…m cache

During signup, SyncSecrets populates the LevelDB cache with only the
desktop device before the paper key is provisioned. SyncSecretsFromCache
then finds a valid cache (desktop has non-zero LastUsedTime), skips the
network sync, and the paper device ends up absent from lastUsedTimes,
leaving LastUsedTime = 0.

Fix: after building lastUsedTimes from cache, scan non-revoked devices.
If any is missing, call SyncSecretsForce once to get fresh data covering
all provisioned devices.
@chrisnojima chrisnojima merged commit dc7df5c into nojima/HOTPOT-next-670-clean-2 Jun 3, 2026
1 check passed
@chrisnojima chrisnojima deleted the nojima/HOTPOT-faster-devices branch June 3, 2026 20:30
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.

3 participants