Skip to content

AO3-4495 Cache the bookmark counts #2459

Merged
merged 1 commit into from May 15, 2016

2 participants

@zz9pzza zz9pzza Revert "Revert "AO3-4495 Cache the bookmark counts""
e9acc90
@houndci-bot houndci-bot commented on the diff May 14, 2016
lib/bookmark_count_caching.rb
@@ -0,0 +1,15 @@
+module BookmarkCountCaching
+ def key_for_public_bookmarks_count
+ "/v1/public_bookmarks_count/#{self.id}"
+ end
+
+ def public_bookmarks_count
+ Rails.cache.fetch(self.key_for_public_bookmarks_count) do
+ self.bookmarks.is_public.count
+ end
+ end
+
+ def invalidate_public_bookmarks_count
+ Rails.cache.delete(self.key_for_public_bookmarks_count)
@houndci-bot
houndci-bot added a note May 14, 2016

Redundant self detected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@houndci-bot houndci-bot commented on the diff May 14, 2016
lib/bookmark_count_caching.rb
@@ -0,0 +1,15 @@
+module BookmarkCountCaching
+ def key_for_public_bookmarks_count
+ "/v1/public_bookmarks_count/#{self.id}"
+ end
+
+ def public_bookmarks_count
+ Rails.cache.fetch(self.key_for_public_bookmarks_count) do
+ self.bookmarks.is_public.count
@houndci-bot
houndci-bot added a note May 14, 2016

Redundant self detected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@houndci-bot houndci-bot commented on the diff May 14, 2016
lib/bookmark_count_caching.rb
@@ -0,0 +1,15 @@
+module BookmarkCountCaching
+ def key_for_public_bookmarks_count
+ "/v1/public_bookmarks_count/#{self.id}"
@houndci-bot
houndci-bot added a note May 14, 2016

Redundant self detected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@houndci-bot houndci-bot commented on the diff May 14, 2016
lib/bookmark_count_caching.rb
@@ -0,0 +1,15 @@
+module BookmarkCountCaching
+ def key_for_public_bookmarks_count
+ "/v1/public_bookmarks_count/#{self.id}"
+ end
+
+ def public_bookmarks_count
+ Rails.cache.fetch(self.key_for_public_bookmarks_count) do
@houndci-bot
houndci-bot added a note May 14, 2016

Redundant self detected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@houndci-bot houndci-bot commented on the diff May 14, 2016
app/models/bookmark.rb
@@ -86,6 +86,15 @@ class Bookmark < ActiveRecord::Base
# Use the current user to determine what works are visible
scope :visible, visible_to_user(User.current_user)
+ before_destroy :invalidate_bookmark_count
+ after_save :invalidate_bookmark_count
+
+ def invalidate_bookmark_count
+ if self.bookmarkable_type == 'Work'
+ Work.find(self.bookmarkable_id).invalidate_public_bookmarks_count
@houndci-bot
houndci-bot added a note May 14, 2016

Redundant self detected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@houndci-bot houndci-bot commented on the diff May 14, 2016
app/models/bookmark.rb
@@ -86,6 +86,15 @@ class Bookmark < ActiveRecord::Base
# Use the current user to determine what works are visible
scope :visible, visible_to_user(User.current_user)
+ before_destroy :invalidate_bookmark_count
+ after_save :invalidate_bookmark_count
+
+ def invalidate_bookmark_count
+ if self.bookmarkable_type == 'Work'
@houndci-bot
houndci-bot added a note May 14, 2016

Redundant self detected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@zz9pzza zz9pzza merged commit 70f1aa7 into master May 15, 2016

3 of 4 checks passed

Details continuous-integration/travis-ci/push The Travis CI build could not complete due to an error
Details continuous-integration/codeship Build succeeded
Details continuous-integration/travis-ci/pr The Travis CI build passed
hound 6 violations found.
@zz9pzza zz9pzza deleted the revert-2454-revert-2367-AO3-4495 branch May 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.