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

fix(project-tree): split unfiled loading #28761

Merged
merged 2 commits into from
Feb 15, 2025
Merged

Conversation

mariusandra
Copy link
Collaborator

Problem

The tree-view flag doesn't load for our team as we have too many unsaved insights.

Changes

  • Hide unsaved insights
  • Split unfiled loading by type

Even this new approach is a temporary one. We should build this tree out beforehand, and integrate into the products.

This should however make something load for our team in production.

Does this work well for both Cloud and self-hosted?

Yep

How did you test this code?

Added a test for API filtering, tested locally in the browser

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This PR improves project tree loading performance by splitting unfiled item loading and filtering out unsaved insights, particularly addressing issues with large datasets.

  • Added type filtering in /posthog/api/file_system.py with new UnfiledFilesQuerySerializer to load unfiled items by type
  • Modified /posthog/models/file_system.py to filter insights with saved=True and support type-specific collection
  • Updated /frontend/src/layout/navigation-3000/components/projectTreeLogic.tsx to load unfiled items separately by type with concurrent loading states
  • Added test_unfiled_endpoint_with_type_filtering in /posthog/api/test/test_file_system.py to verify type filtering functionality

5 file(s) reviewed, 5 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines 279 to 282
loadSavedItems: async () => {
const response = await api.fileSystem.list()
return response.results
return [...values.savedItems, ...response.results]
},
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Potential issue with duplicate items since existing items are concatenated with new results without deduplication

Suggested change
loadSavedItems: async () => {
const response = await api.fileSystem.list()
return response.results
return [...values.savedItems, ...response.results]
},
loadSavedItems: async () => {
const response = await api.fileSystem.list()
return response.results
},

Comment on lines +289 to 291
const response = await api.fileSystem.unfiled(type)
return [...values.allUnfiledItems, ...response.results]
},
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Same duplication issue as above - concatenating results without deduplication could lead to duplicate entries in allUnfiledItems

Suggested change
const response = await api.fileSystem.unfiled(type)
return [...values.allUnfiledItems, ...response.results]
},
const response = await api.fileSystem.unfiled(type)
return response.results
},

Comment on lines +134 to +137
# Check that the type filtering works
response = self.client.get(f"/api/projects/{self.team.id}/file_system/unfiled/?type=feature_flag")
self.assertEqual(response.status_code, status.HTTP_200_OK, response.json())
self.assertEqual(response.json()["count"], 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: test should also verify that other types return 0 results and that invalid types return an appropriate error response

Comment on lines +57 to +59
type = serializers.ChoiceField(
choices=[(choice.value, choice.value) for choice in FileSystemType], required=False, allow_blank=True
)
Copy link
Contributor

Choose a reason for hiding this comment

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

style: choices should be defined as a class constant to avoid recreating the list on every serializer instantiation

Comment on lines +150 to +161
def collect(self, file_type: FileSystemType) -> list[FileSystem]:
if file_type == FileSystemType.FEATURE_FLAG:
return self.collect_feature_flags()
elif file_type == FileSystemType.EXPERIMENT:
return self.collect_experiments()
elif file_type == FileSystemType.INSIGHT:
return self.collect_insights()
elif file_type == FileSystemType.DASHBOARD:
return self.collect_dashboards()
elif file_type == FileSystemType.NOTEBOOK:
return self.collect_notebooks()
return []
Copy link
Contributor

Choose a reason for hiding this comment

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

style: no error handling for invalid FileSystemType values - could return unexpected empty list

Copy link
Contributor

github-actions bot commented Feb 15, 2025

Size Change: +48 B (0%)

Total Size: 1.21 MB

ℹ️ View Unchanged
Filename Size Change
frontend/dist/toolbar.js 1.21 MB +48 B (0%)

compressed-size-action

@mariusandra mariusandra enabled auto-merge (squash) February 15, 2025 12:58
@mariusandra mariusandra merged commit 9becd3a into master Feb 15, 2025
104 checks passed
@mariusandra mariusandra deleted the file-loading-split branch February 15, 2025 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants