Commit Graph
11 Commits
Author SHA1 Message Date
Shivam Mishra 3e65534e68 refactor: fold cache revalidation into the event dispatcher 2026-06-10 12:59:26 +05:30
Shivam Mishra 343b25842a refactor: replace teams merge mutation with full replace 2026-06-10 12:54:42 +05:30
Shivam Mishra f452b88e8d refactor: simplify boot cache hydration to a paint-only step 2026-06-10 12:37:11 +05:30
Shivam Mishra 91f2df8834 refactor: share cache revalidation dispatch 2026-06-08 18:47:42 +05:30
Shivam Mishra b8bca46ba8 fix: address cache revalidation feedback 2026-05-29 16:28:19 +05:30
Shivam Mishra c929319045 feat: cache custom attributes in IDB 2026-05-27 12:45:30 +05:30
Shivam Mishra 5cb517612f feat: flush IndexedDB cache on DATA_VERSION bump
The idempotent upgrade only created missing object stores, so bumping
DATA_VERSION no longer reset bad or stale data — it just added stores. This
restores a bump as a true global cache flush: the upgrade now clears every
existing store before recreating any missing ones, so shipping a version
bump forces all clients to refetch fresh on next boot.

Gated on oldVersion > 0 so fresh installs skip the flush, and clearing
before creating means only pre-existing stores are touched. This is the
break-glass lever for the one non-self-healing failure mode (non-empty
store holding wrong-shaped data paired with a matching cache key), e.g.
after a serializer shape change shipped without a version bump.
2026-05-27 12:31:51 +05:30
Shivam Mishra 4633b49c39 feat: hydrate Vuex stores from IndexedDB on boot
Cached fetches no longer issue a /cache_keys preflight per call. The client
trusts whatever it has in IDB and keeps it fresh through ActionCable
broadcasts and the existing reconnect-time batch revalidate.

On warm boots a new hydrateStoresFromCache helper seeds Vuex from IDB
before ActionCable connects, so inboxes, labels, teams, canned responses,
and agents render immediately from cache. The helper snapshots local cache
keys before fetching server keys — without that ordering the comparison
would always see "fresh" against the just-written key and stale data would
be served forever. Stale entries are revalidated in the background; cold
devices stay on the network-fetch path with no regression.

Also awaits replace inside refetchAndCommit so the data write completes
before the cache key is persisted, closing a window where a concurrent
reader could see a fresh key paired with stale data.
2026-05-21 17:22:04 +05:30
Shivam Mishra 0ae3a82339 feat: drive IndexedDB cache layer from a single registry
Introduces cacheableModels.js as the source of truth for which models the
client caches in IDB and how to dispatch their revalidate actions. DataManager
derives modelsToSync from the registry and creates object stores
idempotently, so adding new cached models needs only one place to change
plus a one-time DATA_VERSION bump.

Also fixes two latent bugs that the upcoming boot-hydration relies on:
setCacheKeys now awaits all per-key writes (was async-forEach with no await),
and replace awaits clear before push (avoids ConstraintError on rapid
refetches).
2026-05-21 17:21:33 +05:30
ea7898d113 feat: fallback to DB localStorage for idb names (#8682)
Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
2024-01-15 15:08:15 +05:30
Shivam MishraandGitHub 00ee0478eb feat: IndexedDB based caching for labels, inboxes and teams [CW-50] (#6710)
* feat: allow caching of labels in the account scope

* feat: send cache keys in account json response

* feat: kickstart web worker

* feat: setup basic architecture for workers

* feat: install idb

* feat: add datamanger

* fix: typos

* refactor: rename method

* feat: make init db a manual step

* refactor: separate accountIdFromRoute

* feat: cache enabled API client

* feat: enable caching for inboxes and labels

* feat: enable cache for team

* feat: manage exceptions for team

* feat: add team to data manager

* feat: add a generic listener

* refactor: send only cache keys

* refactor: separate validate method

* feat: add listeners

* feat: add event for revalidate

* feat: add cache keys endpoint

* refactor: fetch cache keys instead of full account data

* fix: key pattern

* feat: don't fetch account for cache_keys

* fix: cache key base class

* refactor: cache keys helper

* feat: add helper

* fix: cache-key update logic

* feat: delete indexeddb on logout

* feat: remove worker.js

* refactor: move data-manager

* refactor: name of file

* feat: add test for DataManager

* refactor: add fake idb to jest setup

* test: cache keys helper

* test: cache keys helper

* test: cache_keys in accounts controller

* refactor: remove cache_keys context

* feat: add policy for cache-keys
2023-03-27 12:16:25 +05:30