From ebcf3c73bd515a4884961999ef7d33edaba93d57 Mon Sep 17 00:00:00 2001 From: Andreas Brandl Date: Fri, 23 Feb 2018 20:33:16 +0100 Subject: Track which projects a user contributed to. Closes #43460. --- app/models/event.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'app/models/event.rb') diff --git a/app/models/event.rb b/app/models/event.rb index 75538ba196c..f0cc99a9242 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -65,6 +65,7 @@ class Event < ActiveRecord::Base # Callbacks after_create :reset_project_activity after_create :set_last_repository_updated_at, if: :push? + after_create :track_user_contributed_projects # Scopes scope :recent, -> { reorder(id: :desc) } @@ -389,4 +390,8 @@ class Event < ActiveRecord::Base Project.unscoped.where(id: project_id) .update_all(last_repository_updated_at: created_at) end + + def track_user_contributed_projects + UserContributedProjects.track(self) + end end -- cgit v1.2.1 From 375a5c9f1e69a5fbf49a98cecc7f0c0cb61df989 Mon Sep 17 00:00:00 2001 From: Andreas Brandl Date: Mon, 26 Feb 2018 16:44:35 +0100 Subject: Only track contributions if table is available. This is due to the problem that the callback can be called while running an earlier database schema version (for example during earlier migrations). We work around this by checking the current schema version and only track contributions if the table is available. --- app/models/event.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'app/models/event.rb') diff --git a/app/models/event.rb b/app/models/event.rb index f0cc99a9242..e855ed02274 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -392,6 +392,9 @@ class Event < ActiveRecord::Base end def track_user_contributed_projects - UserContributedProjects.track(self) + # Note the call to .available? is due to earlier migrations + # that would otherwise conflict with the call to .track + # (because the table does not exist yet). + UserContributedProjects.track(self) if UserContributedProjects.available? end end -- cgit v1.2.1 From 43b74afd8656df8228c19d5e5e6aee9f87abc244 Mon Sep 17 00:00:00 2001 From: Andreas Brandl Date: Thu, 1 Mar 2018 15:42:04 +0100 Subject: Rename to UserInteractedProjects. This is to avoid a mix-up with the existing concept of 'user contributions'. See `User#contributed_projects` or `Event#contributions`. --- app/models/event.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'app/models/event.rb') diff --git a/app/models/event.rb b/app/models/event.rb index e855ed02274..166c3f1b4b1 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -65,7 +65,7 @@ class Event < ActiveRecord::Base # Callbacks after_create :reset_project_activity after_create :set_last_repository_updated_at, if: :push? - after_create :track_user_contributed_projects + after_create :track_user_interacted_projects # Scopes scope :recent, -> { reorder(id: :desc) } @@ -391,10 +391,10 @@ class Event < ActiveRecord::Base .update_all(last_repository_updated_at: created_at) end - def track_user_contributed_projects + def track_user_interacted_projects # Note the call to .available? is due to earlier migrations # that would otherwise conflict with the call to .track # (because the table does not exist yet). - UserContributedProjects.track(self) if UserContributedProjects.available? + UserInteractedProjects.track(self) if UserInteractedProjects.available? end end -- cgit v1.2.1 From 11a559f7c9ce21b040c3a9c0544169f4885b9fa6 Mon Sep 17 00:00:00 2001 From: Andreas Brandl Date: Sat, 3 Mar 2018 20:00:05 +0100 Subject: Singularize model name. --- app/models/event.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models/event.rb') diff --git a/app/models/event.rb b/app/models/event.rb index 166c3f1b4b1..86a14044bc2 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -395,6 +395,6 @@ class Event < ActiveRecord::Base # Note the call to .available? is due to earlier migrations # that would otherwise conflict with the call to .track # (because the table does not exist yet). - UserInteractedProjects.track(self) if UserInteractedProjects.available? + UserInteractedProject.track(self) if UserInteractedProject.available? end end -- cgit v1.2.1