Skip to content

Commit

Permalink
Merge pull request #13874 from dmarcoux/instrument-request-action-seen
Browse files Browse the repository at this point in the history
Instrument the "Request Action Seen" feature
  • Loading branch information
Dany Marcoux committed Feb 22, 2023
2 parents b637d11 + 6ab92a2 commit 6ecbad8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/api/app/models/bs_request_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class BsRequestAction < ApplicationRecord
belongs_to :target_package_object, class_name: 'Package', foreign_key: 'target_package_id', optional: true
belongs_to :target_project_object, class_name: 'Project', foreign_key: 'target_project_id', optional: true

has_and_belongs_to_many :seen_by_users, class_name: 'User', join_table: :bs_request_actions_seen_by_users
has_many :bs_request_actions_seen_by_users, dependent: :nullify
has_many :seen_by_users, through: :bs_request_actions_seen_by_users, source: :user

scope :bs_request_ids_of_involved_projects, ->(project_ids) { where(target_project_id: project_ids).select(:bs_request_id) }
scope :bs_request_ids_of_involved_packages, ->(package_ids) { where(target_package_id: package_ids).select(:bs_request_id) }
Expand Down
24 changes: 24 additions & 0 deletions src/api/app/models/bs_request_actions_seen_by_user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class BsRequestActionsSeenByUser < ApplicationRecord
belongs_to :bs_request_action
belongs_to :user

after_create do |_record|
RabbitmqBus.send_to_bus('metrics', 'bs_request_action,seen=true count=1')
end

after_destroy do |_record|
RabbitmqBus.send_to_bus('metrics', 'bs_request_action,seen=false count=1')
end
end

# == Schema Information
#
# Table name: bs_request_actions_seen_by_users
#
# bs_request_action_id :bigint not null, indexed => [user_id]
# user_id :bigint not null, indexed => [bs_request_action_id]
#
# Indexes
#
# bs_request_actions_seen_by_users_index (bs_request_action_id,user_id)
#
3 changes: 2 additions & 1 deletion src/api/app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ class User < ApplicationRecord
# users have a n:m relation to roles
has_and_belongs_to_many :roles, -> { distinct }

has_and_belongs_to_many :bs_request_actions_seen, class_name: 'BsRequestAction', join_table: :bs_request_actions_seen_by_users
has_many :bs_request_actions_seen_by_users, dependent: :nullify
has_many :bs_request_actions_seen, through: :bs_request_actions_seen_by_users, source: :bs_request_action

# users have 0..1 user_registration records assigned to them
has_one :user_registration
Expand Down

0 comments on commit 6ecbad8

Please sign in to comment.