-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
feat(discover): add starred manager and endpoint for discover saved queries #123795
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
Changes from all commits
dc28b3f
c18a593
02a75c7
50ad0ed
e495662
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 |
|---|---|---|
|
|
@@ -90,50 +90,47 @@ def reorder_starred_queries( | |
| starred query the user has, not just those of one product. | ||
|
|
||
| Raises: | ||
| ValueError: if ``refs`` is not exactly the set of the user's starred rows, or | ||
| contains a duplicate. | ||
| ValueError: if ``refs`` is not exactly the set of the user's starred rows | ||
| """ | ||
| requested = list(refs) | ||
| if len(requested) != len(set(requested)): | ||
| raise ValueError("Single query cannot take up multiple positions.") | ||
| new_query_positions = list(refs) | ||
|
|
||
| # grab all starred queries in both tables, and map based on SavedQueryRef. | ||
| discover_starred_queries = DiscoverSavedQueryStarred.objects.filter( | ||
| organization=organization, user_id=user_id, position__isnull=False | ||
| ).filter(organization=organization, user_id=user_id, position__isnull=False, starred=True) | ||
| organization=organization, user_id=user_id, position__isnull=False, starred=True | ||
|
Comment on lines
+95
to
+99
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: The Suggested FixStrengthen the validation within Prompt for AI AgentDid we get this right? 👍 / 👎 to inform future reviews.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. THE SERIALIZER DOES THIS |
||
| ) | ||
|
|
||
| explore_starred_queries = ExploreSavedQueryStarred.objects.filter( | ||
| organization=organization, user_id=user_id, position__isnull=False, starred=True | ||
| ) | ||
|
|
||
| combined_starred_queries_map: dict[ | ||
| SavedQueryRef, DiscoverSavedQueryStarred | ExploreSavedQueryStarred | ||
| ] = {} | ||
| existing_query_refs: set[SavedQueryRef] = set() | ||
| for discover_row in discover_starred_queries: | ||
| combined_starred_queries_map[ | ||
| existing_query_refs.add( | ||
| SavedQueryRef(SavedQueryType.DISCOVER, discover_row.discover_saved_query_id) | ||
| ] = discover_row | ||
| ) | ||
|
|
||
| for explore_row in explore_starred_queries: | ||
| combined_starred_queries_map[ | ||
| existing_query_refs.add( | ||
| SavedQueryRef(SavedQueryType.EXPLORE, explore_row.explore_saved_query_id) | ||
| ] = explore_row | ||
| ) | ||
|
|
||
| if combined_starred_queries_map.keys() != set(requested): | ||
| if existing_query_refs != set(new_query_positions): | ||
| raise ValueError("Mismatch between existing and provided starred queries.") | ||
|
|
||
| # normalize positions to 1...N, then assign them in order of the ref sequence provided | ||
| slots = range(1, len(requested) + 1) | ||
| position_map = {ref: position for position, ref in enumerate(new_query_positions, start=1)} | ||
|
|
||
| discover_updates: list[DiscoverSavedQueryStarred] = [] | ||
| explore_updates: list[ExploreSavedQueryStarred] = [] | ||
| for ref, new_position in zip(requested, slots): | ||
| row = combined_starred_queries_map[ref] | ||
| row.position = new_position | ||
| if isinstance(row, ExploreSavedQueryStarred): | ||
| explore_updates.append(row) | ||
| else: | ||
| discover_updates.append(row) | ||
| for discover_row in discover_starred_queries: | ||
| discover_ref = SavedQueryRef(SavedQueryType.DISCOVER, discover_row.discover_saved_query_id) | ||
| discover_row.position = position_map[discover_ref] | ||
| discover_updates.append(discover_row) | ||
|
|
||
| for explore_row in explore_starred_queries: | ||
| explore_ref = SavedQueryRef(SavedQueryType.EXPLORE, explore_row.explore_saved_query_id) | ||
| explore_row.position = position_map[explore_ref] | ||
| explore_updates.append(explore_row) | ||
|
|
||
| ExploreSavedQueryStarred.objects.bulk_update(explore_updates, ["position"]) | ||
| DiscoverSavedQueryStarred.objects.bulk_update(discover_updates, ["position"]) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -159,15 +159,6 @@ def test_moves_a_query_from_the_end_to_the_front(self) -> None: | |
|
|
||
| assert self.ordered_refs() == refs | ||
|
|
||
| def test_rejects_duplicate_ref(self) -> None: | ||
| discover = self.discover_star(1) | ||
| self.explore_star(2) | ||
|
|
||
| ref = SavedQueryRef(SavedQueryType.DISCOVER, discover.discover_saved_query_id) | ||
|
|
||
| with pytest.raises(ValueError, match="multiple positions"): | ||
| utils.reorder_starred_queries(self.org, self.user.id, [ref, ref]) | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above comment^
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not handled by the util function anymore |
||
| def test_rejects_missing_refs(self) -> None: | ||
| # The failure mode this module exists to prevent: a caller that knows about one | ||
| # product sends only its own queries, and the other product's positions are lost. | ||
|
|
||
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.
is this being removed because it's done somewhere else?
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 SavedQueryStarredOrderSerializer handles it, so it was redundant