-
Notifications
You must be signed in to change notification settings - Fork 5
Make load_and_authorize_remix deterministic. #696
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,7 +44,9 @@ def project | |
| end | ||
|
|
||
| def load_and_authorize_remix | ||
| @project = Project.find_by!(remixed_from_id: project.id, user_id: current_user&.id) | ||
| @project = Project.where(remixed_from_id: project.id, user_id: current_user&.id) | ||
| .order(created_at: :desc, updated_at: :desc) | ||
| .first! | ||
|
Comment on lines
+47
to
+49
|
||
| authorize! :show, @project | ||
| end | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ordering here (created_at: :desc, updated_at: :desc) is inconsistent with a similar query in app/controllers/api/lessons_controller.rb:98 which orders remixes by created_at: :asc and only uses created_at for ordering. Consider whether both places should use the same ordering logic, or if there's a specific reason for the difference. If the goal is to consistently return the "most recent" remix, then LessonsController#user_remix should also be updated to use descending order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably both should use the most-recently-created logic. Would appreciate a reviewer's view on this.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😵💫 This is a bit of a muddle, I was hoping that there wasn't that many affected but I saw you said in the epic it's in the 10s of thousands.
I agree on making everywhere that loads projects consistent before we clear the duplicates and put the unique index in.
The thing I'd want to minimize is hiding/losing projects that people have worked on. Picking the most recently created sounds like it might be a good approach, but would it be possible to confirm that? Maybe running a query to see if many duplicate projects with an older created_at have a more recent updated_at?
There are things that hang off of projects ('components' and 'feedback' via 'school_projects') so it might be good to check if they would become hidden.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I agree. I'll do some more analysis on this before we merge it. I have some SQL in my notes that I can adapt to show some of this, I think. I'm about out of brainpower for today but I'll keep you in the loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @zetter-rpf - I have added an SQL query to the related issue for this PR that shows how to identify which students have remixes of which projects.
Fortunately the problem is not as big as first stated - I had forgotten to exclude
_fivetran_deletedrows from the result. It ends up being only 318 student/project pairs, most of which only have 2 duplicates.I don't think
feedbackrecords exist for Scratch projects, since that's a feature ofeditor-uias I understand it and not available in our Scratch Editor?