Skip to content

Commit 1c77b60

Browse files
committed
caching opts
1 parent 7cd177e commit 1c77b60

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

app/models/concerns/has_content.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ module HasContent
3030
has_many :attribute_values, class_name: 'Attribute'
3131

3232
def content
33-
{
33+
@user_content ||= {
3434
characters: characters,
3535
items: items,
3636
locations: locations,
@@ -49,7 +49,7 @@ def content
4949
end
5050

5151
def content_list
52-
[
52+
@user_content_list ||= [
5353
universes,
5454
characters,
5555
items,
@@ -68,7 +68,7 @@ def content_list
6868
end
6969

7070
def content_in_universe universe_id
71-
{
71+
@user_content_in_universe ||= {
7272
characters: characters.in_universe(universe_id),
7373
items: items.in_universe(universe_id),
7474
locations: locations.in_universe(universe_id),
@@ -86,7 +86,7 @@ def content_in_universe universe_id
8686
end
8787

8888
def content_count
89-
[
89+
@user_content_count ||= [
9090
characters.length,
9191
items.length,
9292
locations.length,
@@ -145,7 +145,7 @@ def public_content_count
145145
def recent_content_list
146146
content_types = Rails.application.config.content_types[:all]
147147

148-
content_types.flat_map { |klass|
148+
@user_recent_content_list ||= content_types.flat_map { |klass|
149149
klass.where(user_id: id)
150150
.order(updated_at: :desc)
151151
.limit(10)

app/models/user.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,14 @@ def referrer
3838
has_many :user_content_type_activators
3939

4040
def contributable_universes
41-
# todo email confirmation needs to happy for data safety / privacy (only verified emails)
42-
contributor_by_email = Contributor.where(email: self.email).pluck(:universe_id)
43-
contributor_by_user = Contributor.where(user: self).pluck(:universe_id)
4441

45-
Universe.where(id: contributor_by_email + contributor_by_user)
42+
@user_contributable_universes ||= begin
43+
# todo email confirmation needs to happy for data safety / privacy (only verified emails)
44+
contributor_by_email = Contributor.where(email: self.email).pluck(:universe_id)
45+
contributor_by_user = Contributor.where(user: self).pluck(:universe_id)
46+
47+
Universe.where(id: contributor_by_email + contributor_by_user)
48+
end
4649
end
4750
#TODO: rename this to #{content_type}_shared_with_me and only return contributable content that others own
4851
Rails.application.config.content_types[:all_non_universe].each do |content_type|

0 commit comments

Comments
 (0)