Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Fix thumbnailing remote files #2789

Merged
merged 9 commits into from
Jan 17, 2018
Merged

Fix thumbnailing remote files #2789

merged 9 commits into from
Jan 17, 2018

Conversation

erikjohnston
Copy link
Member

No description provided.

Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

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

looks plausible. I assume this got broken in #2767 ?

@richvdh
Copy link
Member

richvdh commented Jan 16, 2018

are the sytest failures a source of concern?

@richvdh richvdh assigned erikjohnston and unassigned richvdh Jan 16, 2018
@erikjohnston
Copy link
Member Author

looks plausible. I assume this got broken in #2767 ?

Yup

are the sytest failures a source of concern?

The commit ones passed :/ Will have a look.

@erikjohnston erikjohnston assigned richvdh and unassigned erikjohnston Jan 16, 2018
@@ -285,6 +285,7 @@ def _get_remote_media_impl(self, server_name, media_id):
# If we have an entry in the DB, try and look for it
if media_info:
if media_info["quarantined_by"]:
logger.info("Media is quarentined")
Copy link
Member

Choose a reason for hiding this comment

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

quarentined

@@ -85,6 +85,7 @@ def _respond_local_thumbnail(self, request, media_id, width, height,
media_info = yield self.store.get_local_media(media_id)

if not media_info or media_info["quarantined_by"]:
logger.info("Media is quarantined")
Copy link
Member

Choose a reason for hiding this comment

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

we don't know for sure it is quarantined here

@@ -120,6 +122,7 @@ def _select_or_generate_local_thumbnail(self, request, media_id, desired_width,
media_info = yield self.store.get_local_media(media_id)

if not media_info or media_info["quarantined_by"]:
logger.info("Media is quarantined")
Copy link
Member

Choose a reason for hiding this comment

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

ditto

@@ -197,7 +201,7 @@ def _select_or_generate_remote_thumbnail(self, request, server_name, media_id,
yield respond_with_responder(request, responder, t_type, t_length)
return

logger.debug("We don't have a local thumbnail of that size. Generating")
logger.debug("We don't have a remote thumbnail of that size. Generating")
Copy link
Member

Choose a reason for hiding this comment

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

hrm. we're looking for local thumbnails of remote media, no?

@@ -208,6 +212,7 @@ def _select_or_generate_remote_thumbnail(self, request, server_name, media_id,
if file_path:
yield respond_with_file(request, desired_type, file_path)
else:
logger.warn("Failed to generate remote thumbnail")
Copy link
Member

Choose a reason for hiding this comment

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

s/remote/local/ ?

Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

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

I dunno. It looks plausible enough but I'm still failing to grok what the difference between file_id and media_id is.

I'd also appreciate pointers to what this code used to look like before #2767

if server_name:
file_id = media_info["filesystem_id"]
else:
file_id = media_id
Copy link
Member

Choose a reason for hiding this comment

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

the fact that media_info["filesystem_id"] and media_id give different values feels like a red flag to me. why doesn't media_info["filesystem_id"] work for the local 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.

Mainly because we handle local and remote media differently in the DB, and so it returns different things. I think what has happened is that the local/remote code paths were almost entirely separate and have slowly converged over time, making this a bit strange.

Copy link
Member

Choose a reason for hiding this comment

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

Ok. I've now had a bit of a look at how this works. Taking a dict which can take one of two completely unspecified shapes is a horrible API. media_info is only used to pass the media_type and the file_id. Why don't we make both of those explicit parameters?

Copy link
Member

Choose a reason for hiding this comment

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

[Note to self: this is effectively reinstating the condition at https://github.com//pull/2767/files#diff-043e4890d840f3862222c34adf3a9459L476, which constructed the local filename from either file_id or media_id. We now always use file_id so need to get it right]

@richvdh richvdh assigned erikjohnston and unassigned richvdh Jan 16, 2018
@@ -85,7 +85,9 @@ def _respond_local_thumbnail(self, request, media_id, width, height,
media_info = yield self.store.get_local_media(media_id)

if not media_info or media_info["quarantined_by"]:
logger.info("Media is quarantined")
if media_info:
Copy link
Member

Choose a reason for hiding this comment

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

fwiw I'd have gone with:

if not media_info:
    respond_404(request)
    return
if media_info["quarantined_by"]:
    logger.info("Media is quarantined")
    respond_404(request)
    return

but fine

Copy link
Contributor

@krombel krombel Jan 16, 2018

Choose a reason for hiding this comment

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

This is as well inconsistent to lines 127-128. Intended?

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 swear to god I just copied and pasted that. Today is not going well.

@@ -151,7 +151,9 @@ def create_content(self, media_type, upload_name, content, content_length,
"media_length": content_length,
}

yield self._generate_thumbnails(None, media_id, media_id, media_info)
yield self._generate_thumbnails(
None, media_id, media_id, media_info["media_type"],
Copy link
Member

Choose a reason for hiding this comment

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

s/media_info["media_type"]/media_type/

media_info now appears to be redundant here

@@ -534,14 +536,13 @@ def _generate_thumbnails(self, server_name, media_id, file_id, media_info,
media_id (str): The media ID of the content. (This is the same as
the file_id for local content)
file_id (str): Local file ID
media_info (dict)
media_type (str)
Copy link
Member

Choose a reason for hiding this comment

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

doc, please!

@@ -413,7 +415,7 @@ def _download_remote_file(self, server_name, media_id, file_id):
}

yield self._generate_thumbnails(
server_name, media_id, file_id, media_info,
server_name, media_id, file_id, media_info["media_type"],
Copy link
Member

Choose a reason for hiding this comment

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

just media_type

@@ -187,7 +187,8 @@ def _do_preview(self, url, user, ts):
if _is_media(media_info['media_type']):
file_id = media_info['filesystem_id']
dims = yield self.media_repo._generate_thumbnails(
None, file_id, file_id, media_info, url_cache=True,
None, file_id, file_id, media_info["media_type"],
Copy link
Member

Choose a reason for hiding this comment

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

would be nice to factor out a local media_type here too, given the number of times it's referenced, but shrug

Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

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

lgtm

@richvdh
Copy link
Member

richvdh commented Jan 16, 2018

possibly modulo the doc on media_type, but whatevs

@erikjohnston erikjohnston merged commit 3cb2dab into develop Jan 17, 2018
@erikjohnston erikjohnston deleted the erikj/fix_thumbnails branch January 18, 2018 13:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants