Skip to content

Commit

Permalink
refactor: Remove unneeded filter from static asset copy/paste code. (o…
Browse files Browse the repository at this point in the history
  • Loading branch information
bradenmacdonald committed Jul 7, 2023
1 parent 6d6893c commit e705820
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 83 deletions.
8 changes: 0 additions & 8 deletions cms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2728,11 +2728,3 @@

DISCUSSIONS_INCONTEXT_FEEDBACK_URL = ''
DISCUSSIONS_INCONTEXT_LEARNMORE_URL = ''

OPEN_EDX_FILTERS_CONFIG = {
"org.openedx.content_authoring.staged_content.static_filter_source.v1": {
"pipeline": [
"openedx.core.djangoapps.content_staging.filters.IgnoreLargeFiles",
]
}
}
55 changes: 0 additions & 55 deletions openedx/core/djangoapps/content_staging/filters.py

This file was deleted.

32 changes: 12 additions & 20 deletions openedx/core/djangoapps/content_staging/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
from xmodule.modulestore.django import modulestore
from xmodule.modulestore.exceptions import ItemNotFoundError

from .data import CLIPBOARD_PURPOSE, StagedContentFileData, StagedContentStatus
from .filters import StagingStaticAssetFilter
from .data import CLIPBOARD_PURPOSE, StagedContentStatus
from .models import StagedContent, StagedContentFile, UserClipboard
from .serializers import UserClipboardSerializer, PostToClipboardSerializer
from .tasks import delete_expired_clipboards
Expand Down Expand Up @@ -181,7 +180,6 @@ def _save_static_assets_to_clipboard(
"""
Helper method for "post to clipboard" API endpoint. This deals with copying static files into the clipboard.
"""
files_to_save: list[StagedContentFileData] = []
for f in static_files:
source_key = (
StaticContent.get_asset_key_from_path(usage_key.context_key, f.url)
Expand All @@ -201,30 +199,24 @@ def _save_static_assets_to_clipboard(
else:
continue # Skip this file - we don't need a reference to a non-existent file.

# Load the data:
entry = StagedContentFileData(
filename=f.name,
data=content,
source_key=source_key,
md5_hash=md5_hash,
)
files_to_save.append(entry)

# run filters on files_to_save. e.g. remove large files
files_to_save = StagingStaticAssetFilter.run_filter(staged_content=staged_content, file_datas=files_to_save)
# Because we store clipboard files on S3, uploading really large files will be too slow. And it's wasted if
# the copy-paste is just happening within a single course. So for files > 10MB, users must copy the files
# manually. In the future we can consider removing this or making it configurable or filterable.
limit = 10 * 1024 * 1024
if content and len(content) > limit:
content = None

for f in files_to_save:
try:
StagedContentFile.objects.create(
for_content=staged_content,
filename=f.filename,
filename=f.name,
# In some cases (e.g. really large files), we don't store the data here but we still keep track of
# the metadata. You can still use the metadata to determine if the file is already present or not,
# and then either inform the user or find another way to import the file (e.g. if the file still
# exists in the "Files & Uploads" contentstore of the source course, based on source_key_str).
data_file=ContentFile(content=f.data, name=f.filename) if f.data else None,
source_key_str=str(f.source_key) if f.source_key else "",
md5_hash=f.md5_hash or "",
data_file=ContentFile(content=content, name=f.name) if content else None,
source_key_str=str(source_key) if source_key else "",
md5_hash=md5_hash,
)
except Exception: # pylint: disable=broad-except
log.exception(f"Unable to copy static file {f.filename} to clipboard for component {usage_key}")
log.exception(f"Unable to copy static file {f.name} to clipboard for component {usage_key}")

0 comments on commit e705820

Please sign in to comment.