Improving caching #7574
Replies: 3 comments 16 replies
-
In general, I think this also has a lot to do with how the interface is designed and how much user specific functionality do we really need to have e.g. in the listing views. Or could we possibly render the cards without any user specific parts and then add those dynamically once the view is loaded? If we would cache the non-user specific cards separately and the user specific stuff in its own block, it would greatly decrease the memory/space needed to store all of these. I don't know but something seemed weird to me when comparing the view render time to the GraphQL API running the same query for the proposals listing (which completes successfully in few seconds for 20 items): Show the GraphQL query
An important thing to note here is that right now it is not possible to fetch the followers of the proposal or its authors through the API and also it's not possible to fetch the following state of the current user for these records. So, what about removing the following actions in the views from these two places (I removed these lines): decidim/decidim-core/app/cells/decidim/author/profile_minicard.erb Lines 10 to 24 in b0d9d24 I first ran 10 requests with these removed using Then, I reverted the change and ran the same 10 requests using The requests were run in the development mode and without caching, both cases running on the exact same configuration. |
Beta Was this translation helpful? Give feedback.
-
In the Trailblazer book apotonick (Trailblazer's creator) mentions using a CacheVersion pattern for cell caching:
Example implementation: class Grid < Cell::Concept cache
:show do
CacheVersion.for("thing/cell/grid")
end
class CacheVersion < ActiveRecord::Base
def self.for(name)
where(name: name).first or create(name: name)
end
def cache_key # called in AS::Cache#retrieve_cache_key.
updated_at
end
def expire!
update_attribute(:updated_at, (updated_at || Time.now) + 1.second)
end
create_table "cache_versions" do |t|
t.string "name"
t.datetime "updated_at"
end He then describes expiring it in an class Thing::Create < Trailblazer::Operation
callback :default, Callback::Default
module Thing::Callback
class Default < Disposable::Callback::Group
on_change :expire_cache!
def expire_cache!(thing, *)
CacheVersion.for("thing/cell/grid").expire!
end Does anyone think this could improve things at all? (I have to admit I don't fully understand how this alternative approach would map to Decidim's specific case, but thought it might be worth discussing) |
Beta Was this translation helpful? Give feedback.
-
Because we are using a lot of cells, we have situations where a cell like CommentCell, is actually rendering other cells like : report button (Where we aim the relation between current user and the resource in question), also the author of the comment (a cell where we display author specific data and current_user's relation ), and this multiple rendering is causing the cache to be slow as we need to build very complex cache keys like :
Apart of those queries, we also have the queries related to upvotes or downvotes which is being used in an unoptimal way and also other queries. In order to adopt a more efficient cache, we need to split somehow the caching of the resource and the cache of other things that could be impacted by the current user that is being logged in.
|
Beta Was this translation helpful? Give feedback.
-
@ahukkanen just posted some useful findings on an issue from last year for defining a caching strategy that was posted by @armandfardeau, and @alecslupu has also done some analysis of caching that he published on this google doc.
Thought it'd be a good idea to have a go-to place with all the findings, and where the discussion can be continued as well, here.
(@mrcasals and @andreslucena were also involved on that issue discussion)
Beta Was this translation helpful? Give feedback.
All reactions