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
This commit is contained in:
@@ -26,6 +26,7 @@ class Account < ApplicationRecord
|
||||
include FlagShihTzu
|
||||
include Reportable
|
||||
include Featurable
|
||||
include CacheKeys
|
||||
|
||||
DEFAULT_QUERY_SETTING = {
|
||||
flag_query_mode: :bit_operator,
|
||||
|
||||
13
app/models/concerns/account_cache_revalidator.rb
Normal file
13
app/models/concerns/account_cache_revalidator.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
module AccountCacheRevalidator
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
after_save :update_account_cache
|
||||
after_destroy :update_account_cache
|
||||
after_create :update_account_cache
|
||||
end
|
||||
|
||||
def update_account_cache
|
||||
account.update_cache_key(self.class.name.underscore)
|
||||
end
|
||||
end
|
||||
32
app/models/concerns/cache_keys.rb
Normal file
32
app/models/concerns/cache_keys.rb
Normal file
@@ -0,0 +1,32 @@
|
||||
module CacheKeys
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
include CacheKeysHelper
|
||||
include Events::Types
|
||||
|
||||
def cache_keys
|
||||
{
|
||||
label: fetch_value_for_key(id, Label.name.underscore),
|
||||
inbox: fetch_value_for_key(id, Inbox.name.underscore),
|
||||
team: fetch_value_for_key(id, Team.name.underscore)
|
||||
}
|
||||
end
|
||||
|
||||
def invalidate_cache_key_for(key)
|
||||
prefixed_cache_key = get_prefixed_cache_key(id, key)
|
||||
Redis::Alfred.del(prefixed_cache_key)
|
||||
dispatch_cache_udpate_event
|
||||
end
|
||||
|
||||
def update_cache_key(key)
|
||||
prefixed_cache_key = get_prefixed_cache_key(id, key)
|
||||
Redis::Alfred.set(prefixed_cache_key, Time.now.utc.to_i)
|
||||
dispatch_cache_udpate_event
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def dispatch_cache_udpate_event
|
||||
Rails.configuration.dispatcher.dispatch(ACCOUNT_CACHE_INVALIDATED, Time.zone.now, cache_keys: cache_keys, account: self)
|
||||
end
|
||||
end
|
||||
@@ -34,6 +34,7 @@ class Inbox < ApplicationRecord
|
||||
include Reportable
|
||||
include Avatarable
|
||||
include OutOfOffisable
|
||||
include AccountCacheRevalidator
|
||||
|
||||
# Not allowing characters:
|
||||
validates :name, presence: true
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
#
|
||||
class Label < ApplicationRecord
|
||||
include RegexHelper
|
||||
include AccountCacheRevalidator
|
||||
|
||||
belongs_to :account
|
||||
|
||||
validates :title,
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
# index_teams_on_name_and_account_id (name,account_id) UNIQUE
|
||||
#
|
||||
class Team < ApplicationRecord
|
||||
include AccountCacheRevalidator
|
||||
|
||||
belongs_to :account
|
||||
has_many :team_members, dependent: :destroy_async
|
||||
has_many :members, through: :team_members, source: :user
|
||||
|
||||
Reference in New Issue
Block a user