From 3950c2b6c4667d1e504843fcace6528764fbdc55 Mon Sep 17 00:00:00 2001 From: Patrick Gleeson Date: Fri, 18 Oct 2024 12:12:22 +0100 Subject: [PATCH 1/3] Go back to telling app store about new versions immediately --- app/models/event.rb | 1 - app/models/event/new_version.rb | 2 +- ...1018110747_back_fill_new_version_notifications.rb | 12 ++++++++++++ db/schema.rb | 2 +- 4 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20241018110747_back_fill_new_version_notifications.rb diff --git a/app/models/event.rb b/app/models/event.rb index fbb5d403d..0e83ea6f1 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -24,7 +24,6 @@ class Event < ApplicationRecord LOCAL_EVENTS = [ 'Event::DraftDecision', - 'Event::NewVersion', 'Event::Edit', 'Event::Note', 'Event::UndoEdit', diff --git a/app/models/event/new_version.rb b/app/models/event/new_version.rb index 3fd0fd04c..98259685b 100644 --- a/app/models/event/new_version.rb +++ b/app/models/event/new_version.rb @@ -1,7 +1,7 @@ class Event class NewVersion < Event def self.build(submission:) - create(submission: submission, submission_version: submission.current_version) + create(submission: submission, submission_version: submission.current_version).tap(&:notify) end def body diff --git a/db/migrate/20241018110747_back_fill_new_version_notifications.rb b/db/migrate/20241018110747_back_fill_new_version_notifications.rb new file mode 100644 index 000000000..9eeda48a8 --- /dev/null +++ b/db/migrate/20241018110747_back_fill_new_version_notifications.rb @@ -0,0 +1,12 @@ +class BackFillNewVersionNotifications < ActiveRecord::Migration[7.1] + def change + # Unassessed submissions haven't been pushing their new version events to the app + # store recently. Once they are assessed or sent back those events get synced, + # so it's only the ones that are still awaiting assessment that could be out + # of sync + Submission.where(state: %w[submitted provider_updated]).find_each do |submission| + last_new_version_event = submission.events.where(event_type: 'Event::NewVersion').order(:created_at).last + last_new_version_event&.notify + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 6b0101e7c..ea0bbf2a0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_10_15_110647) do +ActiveRecord::Schema[7.1].define(version: 2024_10_18_110747) do # These are extensions that must be enabled in order to support this database enable_extension "citext" enable_extension "plpgsql" From 2fd9665eb212762a649987d3e2a33484e75f59f5 Mon Sep 17 00:00:00 2001 From: Patrick Gleeson Date: Fri, 18 Oct 2024 12:15:02 +0100 Subject: [PATCH 2/3] Add comment --- app/models/event/new_version.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/models/event/new_version.rb b/app/models/event/new_version.rb index 98259685b..00d5ee548 100644 --- a/app/models/event/new_version.rb +++ b/app/models/event/new_version.rb @@ -1,6 +1,8 @@ class Event class NewVersion < Event def self.build(submission:) + # We notify the app store immediately of a new version, because its analytics mechanism + # depends on having new version events available. create(submission: submission, submission_version: submission.current_version).tap(&:notify) end From ba29991542e9db29043d46aef3b5130b580a8e8d Mon Sep 17 00:00:00 2001 From: Patrick Gleeson Date: Fri, 18 Oct 2024 14:13:21 +0100 Subject: [PATCH 3/3] More comment; --- app/models/event.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/models/event.rb b/app/models/event.rb index 0e83ea6f1..d626e8fba 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -22,6 +22,15 @@ class Event < ApplicationRecord 'Event::DeleteAdjustments', ].freeze + # These are events that we know can exist in our local database for a significant + # period without existing in the app store database. All other events are either + # synced to the app store immediately after creation via a `.notify` call, or + # only created as part of a larger action that is followed immediately by a + # call to `NotifyAppStore` which syncs all events anyway. + # It is important to keep track of these so that we can infer what the app + # store thinks the latest event date is (so that the 'last updated' date + # we display in the UI is consistent with the value the app store uses + # for sorting and filtering search results) LOCAL_EVENTS = [ 'Event::DraftDecision', 'Event::Edit',