gotosocial icon indicating copy to clipboard operation
gotosocial copied to clipboard

[feature] S3 browser caching

Open LittleFox94 opened this issue 1 year ago • 6 comments

Current S3 handling prevents any caching of media attachments, because we have a new URL every time we request a piece of media (as it includes a signature for auth/authz). This is especially problematic with browsers.

There is at least one way to work around this problem: instead of generating a URL that is valid "for $x minutes starting now", we could generate one that is valid until a semi-fixed timestamp. That semi-fixed timestamp could be something like "next hour from now, minute 42 second 23", giving us an URL that is valid for one hour and does not change, regardless of the time when you get it. See here for some more: https://stackoverflow.com/a/56543573/2537210

Proposal

When media is requested by a local, authenticated user, we hand out signed URLs for a semi-fixed timestamp of "$tomorrow $fixed-time". This URL is stored in database and every local authenticated user requesting that media gets redirected to this URL.

With this we would have a up-to-24h cache, much better than no cache at all.

LittleFox94 avatar Sep 28 '22 21:09 LittleFox94

That seems sensible!

tsmethurst avatar Sep 29 '22 10:09 tsmethurst

I started brainstorming this and i don't think we even need it to be handled by the database. just a ttl cache of presigned fetch urls would do the trick

NyaaaWhatsUpDoc avatar Oct 01 '22 16:10 NyaaaWhatsUpDoc

Where would that cache be stored?

LittleFox94 avatar Oct 01 '22 19:10 LittleFox94

In memory. We don't support running as a cluster so it's not an issue. Worst case it gets restarted, lose the cache and regenerate them again when necessary.

Or is there something I'm not seeing here?

NyaaaWhatsUpDoc avatar Oct 01 '22 23:10 NyaaaWhatsUpDoc

We don't support running as a cluster so it's not an issue.

Oh, we don't? What's preventing that if I have the database and media storage external (postgresql and S3)?

LittleFox94 avatar Oct 01 '22 23:10 LittleFox94

A few things: mainly caching, and the way the go-fed/activity library is designed and how we have then implemented ourselves around it. We'd have to rearchitect a lot of things to support it

NyaaaWhatsUpDoc avatar Oct 02 '22 04:10 NyaaaWhatsUpDoc

closed by https://github.com/superseriousbusiness/gotosocial/pull/1194

tsmethurst avatar Dec 03 '22 10:12 tsmethurst