Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve caching for read_mark_global #22

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/unread/reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ module Reader
module InstanceMethods
def read_mark_global(klass)
instance_var_name = "@read_mark_global_#{klass.name.gsub('::','_')}"
instance_variable_get(instance_var_name) || begin # memoize
if instance_variables.include?(instance_var_name.to_sym)
instance_variable_get(instance_var_name)
else # memoize
obj = self.read_marks.where(:readable_type => klass.base_class.name).global.first
instance_variable_set(instance_var_name, obj)
end
Expand Down