Operate on ids to avoid unnecessary loading.

This commit is contained in:
Andreas Brandl 2018-03-05 16:50:05 +01:00
parent 11a559f7c9
commit 9ebbcb8f8b
2 changed files with 5 additions and 5 deletions

View file

@ -2,8 +2,8 @@ class UserInteractedProject < ActiveRecord::Base
belongs_to :user
belongs_to :project
validates :project, presence: true
validates :user, presence: true
validates :project_id, presence: true
validates :user_id, presence: true
CACHE_EXPIRY_TIME = 1.day
@ -15,7 +15,7 @@ class UserInteractedProject < ActiveRecord::Base
# For events without a project, we simply don't care.
# An example of this is the creation of a snippet (which
# is not related to any project).
return unless event.project
return unless event.project_id
# This is a precaution because the cache lookup
# will work just fine without an author.

View file

@ -55,6 +55,6 @@ describe UserInteractedProject do
end
end
it { is_expected.to validate_presence_of(:project) }
it { is_expected.to validate_presence_of(:user) }
it { is_expected.to validate_presence_of(:project_id) }
it { is_expected.to validate_presence_of(:user_id) }
end