Update accepted_at when registrations are accepted - #14124
Conversation
gregorbg
left a comment
There was a problem hiding this comment.
You can actually deal with marking accepted_at through a before_save hook.
Look at how mark_registered_at does it, implementing a similar mark_registered_at should be easy.
Regarding the use of accepted_by, do you currently need this (urgently) for your use-case? I would like to figure out a cleaner solution for this (maybe polymorphism) in a different PR before going with your if user_id.to_i.positive? hack.
|
Thanks for the |
|
I think we should just drop accepted at and just use the registration history. that's what it is for |
Yes, but this value is still a useful "aggregate". Just like with live results, you can just issue a By the same token, I would argue that I will not agree to any arbitrary change like Can this convince you? |
|
I get that. But just for one call when submitting results? I would agree if this is a common route and not just one that is called once per competition. |
gregorbg
left a comment
There was a problem hiding this comment.
Now you've succesfully disabled Rubocop in order to move the hook and its helper function below the two other hooks, but you still managed to wedge it between the two hooks and their helper function.
Please make a calm, conscious decision about where to place the hook so that it doesn't "cut" between any existing hooks and their helpers.
That may be the case now, but it is easily conceivable that this information is interesting for other use cases as well, because "being accepted" is so crucial and relevant for registrations in general. |
|
Also, if you want to check "has the newcomer check been run after the last person got accepted", then you need to run a MAX over all registrations. If the timestamp itself is computed using a grouped MAX over all (relevant) histories, then suddenly you have a "MAX of a MAX", which means you would need CTEs. And that's awkward/impossible to do in Rails alone, whereas a field like Daniel proposes (a) is already in our schema, meaning he doesn't even have to run a migration, (b) makes the query simple and fluent in Rails directly and (c) can be backfilled for existing V3 registrations thanks to our histories table. |
But being accepted is just derived from the registration_status column. |
|
Why not drop the column and add a last_accepted_at column to competition? Would that not be much more efficient? |
My bad, I should have been specific: "Having been accepted" is crucial information.
This opens a whole can of worms about why are we tracking |
Okay done |
gregorbg
left a comment
There was a problem hiding this comment.
Why didn't you put the hook below def mark_registered_at?
| before_save :mark_accepted_at, if: :trying_to_accept? | ||
| # rubocop:enable Rails/ActiveRecordCallbacksOrder | ||
| private def mark_accepted_at | ||
| self.accepted_at = Time.now.utc |
There was a problem hiding this comment.
| self.accepted_at = Time.now.utc | |
| self.accepted_at = current_time_from_proper_timezone |
There was a problem hiding this comment.
This is a private method that is (unfortunately) only accessible in Rails models, but it is conveniently DB-aware, using the correct timezone from the server settings.
There was a problem hiding this comment.
See mark_registered_at for reference
Okay, moving below |
| .joins(:registration_history_entry) | ||
| .where(key: 'competing_status', value: 'accepted') | ||
| .group('registration_history_entries.registration_id') | ||
| .select('MAX(registration_history_changes.id)') |
There was a problem hiding this comment.
I think you can use Rails .maximum(:id) here, because you're referencing the ID from registration_history_changes, and that's exactly the table that you started your query from (RegistrationHistoryChange)
There was a problem hiding this comment.
I've removed the migration as per other comment. Not having as rake task, instead will run SQL query later.
There was a problem hiding this comment.
This does not need to be a database migration. I think you can move it into a Rake task easily, and run it manually after this code has been deployed
There was a problem hiding this comment.
I've removed the migration as per other comment. Not having as rake task, instead will run SQL query later.
This PR aims in updating the fields
accepted_atandaccepted_byin registrations.Reason why this is updated: I actually need
accepted_atfor another use-case, so since I'm updatingaccepted_at, I thought of doingaccepted_byas well along with it.Reason why I need
accepted_at: While Delegates submit results, I need a way to identify whether they have triggered the newcomer check after the last newcomer has been accepted. To know when was the last registration is accepted,accepted_atfield will be really helpful.