Skip to content

Commit

Permalink
[files] when getting files add a last_modified flag telling the brows…
Browse files Browse the repository at this point in the history
…er to get the file from its cache + refactoring
  • Loading branch information
EvanBldy committed Jul 15, 2024
1 parent 9745413 commit 0a76ba1
Show file tree
Hide file tree
Showing 8 changed files with 225 additions and 250 deletions.
5 changes: 4 additions & 1 deletion zou/app/blueprints/comments/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from flask_jwt_extended import jwt_required

from zou.app.mixin import ArgsMixin
from zou.app.utils import permissions
from zou.app.utils import permissions, date_helpers

from zou.app.services import (
chats_service,
Expand Down Expand Up @@ -80,6 +80,9 @@ def get(self, attachment_file_id, file_name):
as_attachment=False,
download_name=attachment_file["name"],
max_age=config.CLIENT_CACHE_MAX_AGE,
last_modified=date_helpers.get_datetime_from_string(
self.preview_file["updated_at"]
),
)
except Exception:
current_app.logger.error(
Expand Down
10 changes: 5 additions & 5 deletions zou/app/blueprints/crud/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
user_service,
concepts_service,
)
from zou.app.utils import events, fields, date_helpers
from zou.app.utils import events, date_helpers

from werkzeug.exceptions import NotFound

Expand Down Expand Up @@ -187,11 +187,11 @@ def save_version_if_needed(self, shot, previous_shot):
version = None
if frame_in != pframe_in or frame_out != pframe_out or name != pname:
current_user_id = persons_service.get_current_user()["id"]
previous_updated_at = fields.get_date_object(
previous_shot["updated_at"], date_format="%Y-%m-%dT%H:%M:%S"
previous_updated_at = date_helpers.get_datetime_from_string(
previous_shot["updated_at"]
)
updated_at = fields.get_date_object(
shot["updated_at"], date_format="%Y-%m-%dT%H:%M:%S"
updated_at = date_helpers.get_datetime_from_string(
shot["updated_at"]
)
if (
date_helpers.get_date_diff(previous_updated_at, updated_at)
Expand Down
6 changes: 2 additions & 4 deletions zou/app/blueprints/events/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from flask_jwt_extended import jwt_required

from zou.app.mixin import ArgsMixin
from zou.app.utils import fields, permissions
from zou.app.utils import fields, permissions, date_helpers

from zou.app.services import events_service
from zou.app.services.exception import WrongParameterException
Expand Down Expand Up @@ -105,8 +105,6 @@ def get(self):
permissions.check_manager_permissions()
before = None
if args["before"] is not None:
before = fields.get_date_object(
args["before"], "%Y-%m-%dT%H:%M:%S"
)
before = date_helpers.get_datetime_from_string(args["before"])
page_size = args["page_size"]
return events_service.get_last_login_logs(before, page_size)
15 changes: 12 additions & 3 deletions zou/app/blueprints/files/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@


def send_storage_file(
working_file_id, as_attachment=False, max_age=config.CLIENT_CACHE_MAX_AGE
working_file_id,
as_attachment=False,
max_age=config.CLIENT_CACHE_MAX_AGE,
last_modified=None,
):
"""
Send file from storage. If it's not a local storage, cache the file in
Expand Down Expand Up @@ -60,6 +63,7 @@ def send_storage_file(
as_attachment=as_attachment,
download_name=download_name,
max_age=max_age,
last_modified=last_modified,
)
except IOError as e:
current_app.logger.error(e)
Expand Down Expand Up @@ -125,8 +129,13 @@ def get(self, working_file_id):
schema:
type: file
"""
self.check_access(working_file_id)
return send_storage_file(working_file_id)
working_file = self.check_access(working_file_id)
return send_storage_file(
working_file_id,
last_modified=date_helpers.get_datetime_from_string(
working_file["updated_at"]
),
)

@jwt_required()
def post(self, working_file_id):
Expand Down
11 changes: 3 additions & 8 deletions zou/app/blueprints/previews/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@
PreviewFilePreviewResource,
PreviewFileOriginalResource,
PreviewFileTileResource,
CreateOrganisationThumbnailResource,
OrganisationThumbnailResource,
CreateProjectThumbnailResource,
CreateOrganisationThumbnailResource,
ProjectThumbnailResource,
CreatePersonThumbnailResource,
CreateProjectThumbnailResource,
PersonThumbnailResource,
CreatePersonThumbnailResource,
RunningPreviewFiles,
LegacySetMainPreviewResource,
SetMainPreviewResource,
UpdateAnnotationsResource,
UpdatePreviewPositionResource,
Expand Down Expand Up @@ -118,10 +117,6 @@
"/pictures/preview-background-files/<instance_id>.<extension>",
PreviewBackgroundFileResource,
),
(
"/actions/entities/<entity_id>/set-main-preview/<preview_file_id>",
LegacySetMainPreviewResource,
),
(
"/actions/preview-files/<preview_file_id>/set-main-preview",
SetMainPreviewResource,
Expand Down
Loading

0 comments on commit 0a76ba1

Please sign in to comment.