-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Refactor oEmbed previews #10814
Refactor oEmbed previews #10814
Conversation
057d6b4
to
b00f68a
Compare
This makes oEmbed previews more like image / HTML previews and takes beter advantage of the caching layer.
b00f68a
to
3ffaee6
Compare
I think this is ready for review. There's currently two other PRs built on this that might be useful to look at where this is heading (and why we want to refactor this code). |
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.
I don't think I know enough to review this properly, but a couple of comments
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.
looks generally great! a few comments.
|
||
# Use the cache age from the oEmbed result, instead of the HTTP response. | ||
if oembed_response.cache_age is not None: | ||
expiration_ts_ms = oembed_response.cache_age + media_info.created_ts_ms |
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.
should we cap this, to avoid things being cached for ever?
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.
Yes, we definitely should. Do you have any thoughts for a max-age? 24 hours? A week?
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.
I went with 24 hours, but should be easy enough to change. I also chose to apply this to all previews, not just ones from oEmbed. Although other previews currently always use 1 hour:
synapse/synapse/rest/media/v1/preview_url_resource.py
Lines 418 to 420 in 9ffa787
# FIXME: we should calculate a proper expiration based on the | |
# Cache-Control and Expire headers. But for now, assume 1 hour. | |
expires = ONE_HOUR |
A couple of outstanding questions so I put it back on your review queue @richvdh! |
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.
lgtm
Co-authored-by: Richard van der Hoff <[email protected]>
This reworks how we do oEmbed quite a bit, with an eye towards being able to support auto-discovery and other features. It attempts to fit the oEmbed previews a bit better into the preview framework by moving it to a higher level. This allows for us re-using more of the framework we use for generating previews.
_download_file
method and then post-process the result (like we do for HTML).This also updates the tests to be a bit more reasonable.
Related to #2752.