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(issue-views): Update GET endpoint to validate view's projects #84338

Merged
merged 7 commits into from
Feb 6, 2025

Conversation

MichaelSun48
Copy link
Member

This PR updates the GET organization/.../group-search-views endpoint to validate a views projecst before being sent. The logic is:

If your org doesn't have the multi project stream feature (organizations:global-views) any views that have an invalid projects parameter ("All Projects", "My Projects", or len(projects) > 1) will be set to the first project you have, alphabetically.

No validation is necessary for organizations that do have the multi project stream feature.

@MichaelSun48 MichaelSun48 requested a review from a team as a code owner January 30, 2025 21:15
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jan 30, 2025
@MichaelSun48 MichaelSun48 changed the title def(issue-views): Update GET endpoint to validate view's projects feat(issue-views): Update GET endpoint to validate view's projects Jan 30, 2025
Copy link

codecov bot commented Jan 30, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #84338      +/-   ##
==========================================
+ Coverage   87.63%   87.65%   +0.02%     
==========================================
  Files        9584     9597      +13     
  Lines      542887   543709     +822     
  Branches    21271    21271              
==========================================
+ Hits       475745   476613     +868     
+ Misses      66790    66744      -46     
  Partials      352      352              

for view in query:
if view.is_all_projects or view.projects.count() > 1 or view.projects.count() == 0:
view.is_all_projects = False
view.projects.set([pick_default_project(organization, request.user)])
Copy link
Member

Choose a reason for hiding this comment

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

In the worst case this will make a db query for each view - can we make sure this only gets evaluated once?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch, just updated the logic. Should be much more efficient now!

for view in query:
if view.is_all_projects or view.projects.count() > 1 or view.projects.count() == 0:
views_to_updates = []
default_project = pick_default_project(organization, request.user)
Copy link
Member

Choose a reason for hiding this comment

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

Technically this query might not be necessary if all the views have a single project, so we can make this even better if we avoid it in that case

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this is handled by Django's lazy loading of query sets - so if default project is never accessed in the for loop after this, the DB query isn't actually made.

if self.has_global_views is False:
is_all_projects = False

projects = list(obj.projects.values_list("id", flat=True))
Copy link
Member

Choose a reason for hiding this comment

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

Does this make a query for each view? This would be slow for many views and would be better if we could prefetch them in the initial query since we know we'll need it anyway

Copy link
Member Author

Choose a reason for hiding this comment

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

Added! (organization_group_search_views, line 75)

@MichaelSun48 MichaelSun48 merged commit f928557 into master Feb 6, 2025
49 checks passed
@MichaelSun48 MichaelSun48 deleted the msun/issueViews/validateProjectsInGetRequest branch February 6, 2025 19:16
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.

2 participants