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

feat(explore): Adds starred queries backend models and endpoints #88448

Merged
merged 6 commits into from
Apr 3, 2025

Conversation

edwardgou-sentry
Copy link
Contributor

@edwardgou-sentry edwardgou-sentry commented Apr 1, 2025

Adds a ExploreSavedQueryStarred model to support Starred Explore Queries in the new Sentry UI Side Nav.
Includes a ExploreSavedQueryStarredManager to primarily handle validating and managing positioning of Starred items.

Also adds new POST and PUT endpoints that utilizes this new model to star/unstar queries, and to rearrange list order. Updates the GET saved queries endpoint to also return starred status.

A large part of this code was adapted from the GroupSearchViewStarred model from the Issue Views product. There's an opportunity to make a generic Starred model and manager, but I'd like to plan this for a future improvement to not add any new blockers to Issue Views or Explore timelines.

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Apr 1, 2025
Copy link
Contributor

github-actions bot commented Apr 1, 2025

This PR has a migration; here is the generated SQL for src/sentry/explore/migrations/0002_add_starred_explore_query_model.py ()

--
-- Create model ExploreSavedQueryStarred
--
CREATE TABLE "explore_exploresavedquerystarred" ("id" bigint NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, "date_updated" timestamp with time zone NOT NULL, "date_added" timestamp with time zone NOT NULL, "user_id" bigint NOT NULL, "position" smallint NOT NULL CHECK ("position" >= 0), "explore_saved_query_id" bigint NOT NULL, "organization_id" bigint NOT NULL, CONSTRAINT "explore_exploresavedquerystarred_unique_query_position_per_org_user" UNIQUE ("user_id", "organization_id", "position") DEFERRABLE INITIALLY DEFERRED);
ALTER TABLE "explore_exploresavedquerystarred" ADD CONSTRAINT "explore_exploresaved_explore_saved_query__55f1a783_fk_explore_e" FOREIGN KEY ("explore_saved_query_id") REFERENCES "explore_exploresavedquery" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "explore_exploresavedquerystarred" VALIDATE CONSTRAINT "explore_exploresaved_explore_saved_query__55f1a783_fk_explore_e";
ALTER TABLE "explore_exploresavedquerystarred" ADD CONSTRAINT "explore_exploresaved_organization_id_dbbddb21_fk_sentry_or" FOREIGN KEY ("organization_id") REFERENCES "sentry_organization" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "explore_exploresavedquerystarred" VALIDATE CONSTRAINT "explore_exploresaved_organization_id_dbbddb21_fk_sentry_or";
CREATE INDEX CONCURRENTLY "explore_exploresavedquerystarred_user_id_243ad14e" ON "explore_exploresavedquerystarred" ("user_id");
CREATE INDEX CONCURRENTLY "explore_exploresavedquerys_explore_saved_query_id_55f1a783" ON "explore_exploresavedquerystarred" ("explore_saved_query_id");
CREATE INDEX CONCURRENTLY "explore_exploresavedquerystarred_organization_id_dbbddb21" ON "explore_exploresavedquerystarred" ("organization_id");

Copy link

codecov bot commented Apr 1, 2025

Codecov Report

Attention: Patch coverage is 93.39207% with 15 lines in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...y/explore/endpoints/explore_saved_query_starred.py 86.04% 6 Missing ⚠️
.../sentry/explore/endpoints/explore_saved_queries.py 70.00% 3 Missing ⚠️
...ore/endpoints/explore_saved_query_starred_order.py 92.50% 3 Missing ⚠️
src/sentry/explore/models.py 93.75% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master   #88448       +/-   ##
===========================================
+ Coverage   56.24%   87.77%   +31.53%     
===========================================
  Files        9918     9999       +81     
  Lines      563610   566943     +3333     
  Branches    22206    22206               
===========================================
+ Hits       316976   497648   +180672     
+ Misses     246232    68893   -177339     
  Partials      402      402               

@edwardgou-sentry edwardgou-sentry requested review from a team April 1, 2025 22:31
@edwardgou-sentry edwardgou-sentry marked this pull request as ready for review April 1, 2025 22:31
@edwardgou-sentry edwardgou-sentry requested review from a team as code owners April 1, 2025 22:31
Copy link
Member

@wedamija wedamija left a comment

Choose a reason for hiding this comment

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

@MichaelSun48 has been building something similar for saved issue searches. It might be worth you both collaborating a little here, because there are probably a lot of similarities. You might be able to share a lot of code, and just have different models passed through

@edwardgou-sentry
Copy link
Contributor Author

@MichaelSun48 has been building something similar for saved issue searches. It might be worth you both collaborating a little here, because there are probably a lot of similarities. You might be able to share a lot of code, and just have different models passed through

Hey @wedamija , I discussed with @MichaelSun48 about this before working on this PR. There's definitely a lot of similarities. I'm actually just copying some of those existing models and adapting them for explore saved queries.

If we want to share code, we'll probably need to run a migration to merge models/tables. The model manager can probably be updated to be generic easily without additional migrations.

However, I'm avoiding making changes to the existing models for saved issue searches for the moment, because I know that feature is releasing soon and I don't want to introduce a new blocker (Explore Saved queries also has a short timeline). I plan to look into genericizing this code after both issue and explore features get released. Let me know if this is ok, or you have a strong opinion on this.

Copy link
Member

@narsaynorath narsaynorath left a comment

Choose a reason for hiding this comment

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

Code lgtm, I think it's pretty clear what these endpoints and API are intended to do/be used for

@edwardgou-sentry edwardgou-sentry merged commit 8c2282e into master Apr 3, 2025
48 checks passed
@edwardgou-sentry edwardgou-sentry deleted the egou/feat/explore-starred-queries-backend branch April 3, 2025 18:17
Copy link
Member

@wedamija wedamija left a comment

Choose a reason for hiding this comment

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

migration lgtm

andrewshie-sentry pushed a commit that referenced this pull request Apr 8, 2025
)

Adds a `ExploreSavedQueryStarred` model to support Starred Explore
Queries in the new Sentry UI Side Nav.
Includes a `ExploreSavedQueryStarredManager` to primarily handle
validating and managing positioning of Starred items.

Also adds new POST and PUT endpoints that utilizes this new model to
star/unstar queries, and to rearrange list order. Updates the GET saved
queries endpoint to also return starred status.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants