Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add significantly_updated_at attribute to User #1991

Merged
merged 8 commits into from
Nov 25, 2024

Conversation

ethax-ross
Copy link
Collaborator

@ethax-ross ethax-ross commented Nov 19, 2024

Jira-3747

Context

At the moment, we use the User#updated_at to surface changes to lead providers via the API. The issue with this is that actions/changes that lead providers don't care about result in the user being marked as 'updated'. Instead, we want to have an additional updated_at attribute that we can use to surface the changes lead providers care about to the underlying User model.

Changes proposed in this pull request

  • Add significantly_udpated_at attribute to User

We have an updated_at on the User model, however this is updated frequently and for actions that lead providers don't need to care about (such as when a user signs in).

We want to add a second updarted_at attribute that only updates when something significant changes with the User, such as their name, TRN, etc.

As the Application can touch a User we also need this attribute to update when the user is touched.

I opted for significantly_updated_at as the attribute name as opposed to api_updated_at to try and keep it more generic in case we want to surface it elsewhere.

Index the field to ensure endpoints that filter by updated_at will be performant when we switch them to significantly_updated_at`.

  • Switch User migrator to populate significantly_updated_at

We want to populate significantly_udpated_at instead of updated_at as we will be exposing this attribute in the serializers for the lead provider API.

  • Update Participants::Query to use significantly_udpated_at

We want to filter by the significantly_updated_at attribute instead of the updated_at attribute when querying users for the lead provider API. This will prevent insignificant changes to a User resulting in them being re-surfaced in the API.

  • Update ParticipantSerializer to use significant_updated_at

We want to surface the sigificant_updated_at attribute of participants in the lead provider API responses so that providers only see changes/updates when something they care about has changed with the user.

Guidance to review

As it stands any users already in the NPQ reg database that aren't touched as part of the migration will end up with a default significantly_updated_at time of 'now' (when we roll this out). Do we want to backfill to match with the user updated_at for these records?

@ethax-ross ethax-ross force-pushed the 3747-add-significant-updated-at-to-users branch 2 times, most recently from 81c3632 to b225009 Compare November 19, 2024 13:36
Copy link
Contributor

@ethax-ross ethax-ross force-pushed the 3747-add-significant-updated-at-to-users branch from e362d21 to dddd259 Compare November 19, 2024 14:06
@ethax-ross ethax-ross marked this pull request as ready for review November 19, 2024 14:18
@ethax-ross ethax-ross requested a review from a team as a code owner November 19, 2024 14:18
@ethax-ross ethax-ross requested a review from a team November 19, 2024 14:18
Copy link
Contributor

@leandroalemao leandroalemao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's looking good tks.. 👍 I reckon we can backfill significantly_updated_at to be the same as updated_at for the other records as part of the ticket as well?

@@ -58,12 +58,12 @@ def call
active_alert: npq_application.active_alert || user.active_alert,
trn_verified:,
created_at: ecf_user.created_at,
updated_at: ecf_user.updated_at,
significantly_updated_at: ecf_user.updated_at,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we still can keep migrating updated_at over or not?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discussed in person: let's keep both

We have an `updated_at` on the `User` model, however this is updated frequently
and for actions that lead providers don't need to care about (such as when a
user signs in).

We want to add a second `updarted_at` attribute that only updates when
something significant changes with the `User`, such as their name, TRN, etc.

As the `Application` can touch a `User` we also need this attribute to update
when the user is touched.

I opted for `significantly_updated_at` as the attribute name as opposed to
`api_updated_at` to try and keep it more generic in case we want to surface it
elsewhere.

Index the field to ensure endpoints that filter by `updated_at` will be performant when we switch them to `significantly_updated_at`.
We want to populate `significantly_udpated_at` instead of `updated_at` as we
will be exposing this attribute in the serializers for the lead provider API.
We want to filter by the `significantly_updated_at` attribute instead of the
`updated_at` attribute when querying users for the lead provider API. This will
prevent insignificant changes to a `User` resulting in them being re-surfaced
in the API. Update `Participants::Query` and `Applications::Query` to use
`significantly_updated_at`.
We want to surface the `sigificant_updated_at` attribute of participants in the
lead provider API responses so that providers only see changes/updates when
something they care about has changed with the user.
Exclude `significantly_updated_at` from these feature specs.
We want to retain updating `updated_at` on users as well as populating the new
`significantly_updated_at` during the migration.
We want to ensure we don't touch `significantly_updated_at` from the callback
in `User` when performing a migration.
We want to backfill the `significantly_updated_at` using the `updated_at`
attribute of each user.
@ethax-ross ethax-ross force-pushed the 3747-add-significant-updated-at-to-users branch from a51f25b to 8abfaf7 Compare November 22, 2024 16:10
Copy link
Contributor

@leandroalemao leandroalemao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good 👍 tks @ethax-ross 😄

@ethax-ross ethax-ross added this pull request to the merge queue Nov 25, 2024
Merged via the queue into main with commit 7205030 Nov 25, 2024
18 checks passed
@ethax-ross ethax-ross deleted the 3747-add-significant-updated-at-to-users branch November 25, 2024 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants