Created
April 5, 2012 23:10
-
-
Save omarqureshi/2314933 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/app/models/topic.rb b/app/models/topic.rb | |
index c27a174..bcd9d5a 100644 | |
--- a/app/models/topic.rb | |
+++ b/app/models/topic.rb | |
@@ -117,15 +117,55 @@ class Topic < ActiveRecord::Base | |
replies.active.count | |
end | |
+ # Public: Used by views to determine whether the index page needs to | |
+ # be updated. | |
+ # | |
+ # When any topic or post is updated the old cache will just be | |
+ # unused and eventually be removed by memcached. | |
+ # | |
+ # This will also handle users specific needs with regards to the | |
+ # number of topics to display per page and what page the user is | |
+ # currently visiting. | |
+ # | |
+ # current_site - a symbol to say whether the site is :default or | |
+ # :medical | |
+ # current_page - params[:page] from the controller, this should be | |
+ # an integer or a string representing an integer. | |
+ # per_page - params[:per_page] from the controller, this should | |
+ | |
def self.index_cache_path(current_site, current_page, per_page) | |
"topics/?page=#{current_page}&per_page=#{per_page}¤t_site=#{current_site}##{cache_timestamp}" | |
end | |
+ # Public: Used by views to determine whether the show page needs to | |
+ # be updated. | |
+ # | |
+ # When the topic or any of its posts are updated the old cache will | |
+ # just be unused and eventually be removed by memcached. | |
+ # | |
+ # This will also handle users specific needs with regards to the | |
+ # order of posts, how many posts to display on the page and the | |
+ # current page that the user is visiting. | |
+ # | |
+ # current_page - params[:page] from the controller, this should be | |
+ # an integer or a string representing an integer. | |
+ # per_page - params[:per_page] from the controller, this should | |
+ # be an integer or a string representing an integer. | |
+ # posts_order - whether the order of post retrieval is ascending or | |
+ # descending. Should be a string which is either | |
+ # 'ASC' or 'DESC' | |
+ # Returns a unique string for each topic / per page / current page / | |
+ # order combination | |
+ | |
def show_cache_path(current_page, per_page, posts_order) | |
# TODO: check if we need is_monitored? | |
"forums/#{forum.id}/topics/#{id}?page=#{current_page}&per_page=#{per_page}&order=#{posts_order}##{updated_at.to_i}" | |
end | |
+ # Public: Changed every time a topic or post is updated | |
+ # | |
+ # Returns an integer | |
+ | |
def self.cache_timestamp | |
first(:order => "updated_at desc").updated_at.to_i | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment