-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HYC-1934 - Send download events to database (#1108)
* add hycdownloadstat model and migration * update schema after running HycDownloadStat migration * Update DownloadAnalyticsBehavior to push stats to local db * logs, factorybot and logs in create_download_stat * changed phrasing, add new test * test for download tracking within database, rubocop * test to verify download count is incremented for existing table entries * removing repeated mocking in download controller tests and adding a function to return fileset ids * removing some duplicate code, tests for new helper function * specifying uid to avoid conflicts * helper function tests, removing tests with duplicate coverage * pr changes
- Loading branch information
1 parent
3d1a199
commit b9eda36
Showing
7 changed files
with
274 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# frozen_string_literal: true | ||
class HycDownloadStat < ApplicationRecord | ||
scope :with_fileset_id_and_date, ->(fileset_id, start_date, end_date) { where(fileset_id: fileset_id, date: start_date..end_date) } | ||
scope :with_work_id_and_date, ->(work_id, start_date, end_date) { where(work_id: work_id, date: start_date..end_date) } | ||
scope :with_admin_set_id, ->(admin_set_id) { where(admin_set_id: admin_set_id) } | ||
scope :with_work_type, ->(work_type) { where(work_type: work_type) } | ||
|
||
# Additional scopes for flexibility | ||
scope :with_fileset_id, ->(fileset_id) { where(fileset_id: fileset_id) } | ||
scope :with_work_id, ->(work_id) { where(work_id: work_id) } | ||
scope :within_date_range, ->(start_date, end_date) { where(date: start_date..end_date) } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
class CreateHycDownloadStats < ActiveRecord::Migration[6.1] | ||
def change | ||
create_table :hyc_download_stats do |t| | ||
t.string :fileset_id, null: false | ||
t.string :work_id, null: false | ||
t.string :admin_set_id, null: false | ||
t.string :work_type, null: false | ||
t.date :date, null: false | ||
t.integer :download_count, default: 0, null: false | ||
|
||
t.timestamps | ||
end | ||
|
||
add_index :hyc_download_stats, [:fileset_id, :date] | ||
add_index :hyc_download_stats, [:work_id, :date] | ||
add_index :hyc_download_stats, :admin_set_id | ||
add_index :hyc_download_stats, :work_type | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.