-
Notifications
You must be signed in to change notification settings - Fork 262
remove perseus from storage calculations #5601
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
base: unstable
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -349,25 +349,57 @@ def check_feature_flag(self, flag_name): | |
|
|
||
| def check_channel_space(self, channel): | ||
| tree_cte = With(self.get_user_active_trees().distinct(), name="trees") | ||
| files_cte = With( | ||
| tree_cte.join( | ||
| self.files.get_queryset(), contentnode__tree_id=tree_cte.col.tree_id | ||
| ) | ||
| .values("checksum") | ||
|
|
||
| user_files_cte = With( | ||
| self.files.get_queryset() | ||
| .values("checksum", "contentnode_id", "file_format_id") | ||
| .distinct(), | ||
| name="files", | ||
| name="user_files", | ||
| ) | ||
|
|
||
| staging_tree_files = ( | ||
| self.files.filter(contentnode__tree_id=channel.staging_tree.tree_id) | ||
| editable_files_qs = ( | ||
| user_files_cte.queryset() | ||
| .with_cte(tree_cte) | ||
| .with_cte(files_cte) | ||
| .exclude(Exists(files_cte.queryset().filter(checksum=OuterRef("checksum")))) | ||
| .values("checksum") | ||
| .distinct() | ||
| .with_cte(user_files_cte) | ||
| .filter( | ||
| Exists( | ||
| tree_cte.join( | ||
| ContentNode.objects.all(), tree_id=tree_cte.col.tree_id | ||
| ) | ||
| .with_cte(tree_cte) | ||
| .filter(id=OuterRef("contentnode_id")) | ||
| ) | ||
| ) | ||
| ) | ||
|
|
||
| editable_files_qs = self._filter_storage_billable_files(editable_files_qs) | ||
|
|
||
| existing_checksums_cte = With( | ||
| editable_files_qs.values("checksum").distinct(), name="existing_checksums" | ||
| ) | ||
|
|
||
| staging_files_qs = self._filter_storage_billable_files( | ||
| self.files.filter(contentnode__tree_id=channel.staging_tree.tree_id) | ||
| ) | ||
|
|
||
| staging_files_qs = ( | ||
| staging_files_qs.with_cte(tree_cte) | ||
| .with_cte(user_files_cte) | ||
| .with_cte(existing_checksums_cte) | ||
| .exclude( | ||
| Exists( | ||
| existing_checksums_cte.queryset().filter( | ||
| checksum=OuterRef("checksum") | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
|
|
||
| staged_size = float( | ||
| staging_tree_files.aggregate(used=Sum("file_size"))["used"] or 0 | ||
| staging_files_qs.values("checksum") | ||
| .distinct() | ||
| .aggregate(used=Sum("file_size"))["used"] | ||
| or 0 | ||
| ) | ||
|
|
||
| if self.get_available_space() < staged_size: | ||
|
|
@@ -410,13 +442,42 @@ def get_user_active_trees(self): | |
| ) | ||
|
|
||
| def get_user_active_files(self): | ||
| cte = With(self.get_user_active_trees().distinct()) | ||
|
|
||
| return ( | ||
| cte.join(self.files.get_queryset(), contentnode__tree_id=cte.col.tree_id) | ||
| .with_cte(cte) | ||
| .values("checksum") | ||
| .distinct() | ||
| tree_cte = With(self.get_user_active_trees().distinct(), name="trees") | ||
|
|
||
| user_files_cte = With( | ||
| self.files.get_queryset() | ||
| .values("checksum", "contentnode_id", "file_format_id") | ||
| .distinct(), | ||
| name="user_files", | ||
| ) | ||
| file_qs = ( | ||
| user_files_cte.queryset() | ||
| .with_cte(tree_cte) | ||
| .with_cte(user_files_cte) | ||
| .filter( | ||
| Exists( | ||
| tree_cte.join( | ||
| ContentNode.objects.all(), tree_id=tree_cte.col.tree_id | ||
| ) | ||
| .with_cte(tree_cte) | ||
| .filter(id=OuterRef("contentnode_id")) | ||
| ) | ||
| ) | ||
| ) | ||
|
|
||
| files_qs = self._filter_storage_billable_files(file_qs) | ||
|
|
||
| return files_qs.values("checksum").distinct() | ||
|
|
||
| def _filter_storage_billable_files(self, queryset): | ||
| """ | ||
| Perseus exports would not be included in storage calculations. | ||
| """ | ||
| if queryset is None: | ||
| return queryset | ||
| return queryset.exclude(file_format_id__isnull=True).exclude( | ||
| file_format_id=file_formats.PERSEUS | ||
|
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. Not an immediate concern, but just a heads that when QTI assessments are more broadly available, and we are generating QTI ZIP files, then we may need to filter these too (and it would need to be on the format preset, rather than the file format id, because the format id would be 'zip'!) |
||
| ) | ||
|
|
||
| def get_space_used(self, active_files=None): | ||
|
|
||
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.
This still has the same issue as the original queries-- it queries on too many things at once. The
user_files_ctecan be reused for both editable and staged trees. So you can essentially duplicateeditable_files_qsbut instead of joining ontree_ctejust check existence wheretree_id=channel.staging_tree.tree_id.Then in the core
SELECTquery, where it diffs between existing and new checksums, you can also filter offfile_format_id