-
Notifications
You must be signed in to change notification settings - Fork 214
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
Use DB to augment ES hits for related media with required info #3408
Conversation
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.
Thank you for such a quick fix, @dhruvkb ! It works well and matches what we do on another endpoint.
I added non-blocking questions inline.
@@ -267,6 +267,10 @@ def related(self, request, identifier=None, *_, **__): | |||
|
|||
serializer_context = self.get_serializer_context() | |||
|
|||
serializer_class = self.get_serializer() | |||
if serializer_class.needs_db: | |||
results = self.get_db_results(results) |
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.
Do we have any idea of how much getting the db results affects the performance of the searches?
I wonder how we can measure if it's better to get this data from the database, or to keep it in ES indexes and get it from there?
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.
It is a single query to the DB for all results using the field identifier
that's both unique=True
and index=True
. I don't think it is inefficient. Personally I prefer one the way it is rn because we have to query the DB anyway for relational info that can't be stored in ES. Also the amount of relational info will only increase with new projects slated for 2024.
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.
Thank you for the explanation, @dhruvkb , makes sense!
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.
@dhruvkb 100% in agreement here as well, that would be a good thing to document somewhere as the "rationale" of the serialiser approach, prefereably in code or, if not there, then in the API docs, in something of a "design decisions" document. It's similar to the the ES document _id
not being the same as identifier
, for example, in that it's easy to forget why this is the "right" way to do it and then re-ask this same question (or for new folks to ask this question). A "design decisions" doc I think would be a great thing to have in general (to summarise my point 😀).
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.
Actually, rather than a new documentation page, pulling this behaviour into a function that the two view methods can call and adding the rationale in the doc string there would be more resilient to future changes.
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.
Based on the high urgency of this PR, the following reviewers are being gently reminded to review this PR: @krysal Excluding weekend1 days, this PR was ready for review 2 day(s) ago. PRs labelled with high urgency are expected to be reviewed within 2 weekday(s)2. @dhruvkb, if this PR is not ready for a review, please draft it to prevent reviewers from getting further unnecessary pings. Footnotes
|
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.
LGTM! Tested with the first general image result and in main
the mentioned fields are null
and here are correctly filled ✅
http://localhost:50280/v1/images/3d0af15e-5f3a-42f9-8833-1a3d6baf90c3/related/
Given the high priority, I'm going to merge this and we'll solve for #3436 separately (and handle the extraction of common code as a part of that simplification process). |
Fixes
Fixes #3403 by @obulat
Description
This PR uses the DB to augment ES hits for related media with info that's not in ES. It uses the exact same pattern (and for that matter, code) as
get_media_results
.Also updated the related media tests to check for the presence of these fields.
Testing Instructions
Try, and fail, to repro the issue described in #3403 on this branch.
Checklist
Update index.md
).main
) or a parent feature branch.Developer Certificate of Origin
Developer Certificate of Origin