akkoma/lib/pleroma/web/mastodon_api/views
Mark Felder 5da9cbd8a5 RichMedia refactor
Rich Media parsing was previously handled on-demand with a 2 second HTTP request timeout and retained only in Cachex. Every time a Pleroma instance is restarted it will have to request and parse the data for each status with a URL detected. When fetching a batch of statuses they were processed in parallel to attempt to keep the maximum latency at 2 seconds, but often resulted in a timeline appearing to hang during loading due to a URL that could not be successfully reached. URLs which had images links that expire (Amazon AWS) were parsed and inserted with a TTL to ensure the image link would not break.

Rich Media data is now cached in the database and fetched asynchronously. Cachex is used as a read-through cache. When the data becomes available we stream an update to the clients. If the result is returned quickly the experience is almost seamless. Activities were already processed for their Rich Media data during ingestion to warm the cache, so users should not normally encounter the asynchronous loading of the Rich Media data.

Implementation notes:

- The async worker is a Task with a globally unique process name to prevent duplicate processing of the same URL
- The Task will attempt to fetch the data 3 times with increasing sleep time between attempts
- The HTTP request obeys the default HTTP request timeout value instead of 2 seconds
- URLs that cannot be successfully parsed due to an unexpected error receives a negative cache entry for 15 minutes
- URLs that fail with an expected error will receive a negative cache with no TTL
- Activities that have no detected URLs insert a nil value in the Cachex :scrubber_cache so we do not repeat parsing the object content with Floki every time the activity is rendered
- Expiring image URLs are handled with an Oban job
- There is no automatic cleanup of the Rich Media data in the database, but it is safe to delete at any time
- The post draft/preview feature makes the URL processing synchronous so the rendered post preview will have an accurate rendering

Overall performance of timelines and creating new posts which contain URLs is greatly improved.
2024-06-09 17:33:48 +01:00
..
account_view.ex Merge pull request 'Return last_status_at as date, not datetime' (#681) from katafrakt/akkoma:fix-last-status-at into develop 2024-02-17 11:37:19 +00:00
announcement_view.ex Merge branch 'from/upstream-develop/tusooa/server-announcements' into 'develop' (#85) 2022-07-18 13:08:36 +00:00
app_view.ex [#2510] Improved support for app-bound OAuth tokens. Auth-related refactoring. 2021-02-11 15:02:50 +03:00
conversation_view.ex Migrate Pleroma.Web to phoenix 1.6 formats 2023-01-02 03:29:02 +00:00
custom_emoji_view.ex Deprecate Pleroma.Web.base_url/0 2021-05-31 16:48:03 -05:00
filter_view.ex Bump Copyright to 2021 2021-01-13 07:49:50 +01:00
follow_request_view.ex Create real Views for all Controllers 2021-05-29 12:15:57 -05:00
instance_view.ex Use enum empty instead 2023-03-13 03:40:20 +00:00
list_view.ex Bump Copyright to 2021 2021-01-13 07:49:50 +01:00
marker_view.ex Bump Copyright to 2021 2021-01-13 07:49:50 +01:00
media_view.ex Create real Views for all Controllers 2021-05-29 12:15:57 -05:00
notification_view.ex Migrate Pleroma.Web to phoenix 1.6 formats 2023-01-02 03:29:02 +00:00
poll_view.ex fix count of poll voters 2022-11-08 13:50:04 +00:00
report_view.ex Bump Copyright to 2021 2021-01-13 07:49:50 +01:00
scheduled_activity_view.ex expires_in in scheduled status params 2021-02-18 14:59:22 +03:00
status_view.ex RichMedia refactor 2024-06-09 17:33:48 +01:00
subscription_view.ex Bump Copyright to 2021 2021-01-13 07:49:50 +01:00
suggestion_view.ex v2 Suggestions: rudimentary API response 2021-11-26 14:34:10 -06:00
tag_view.ex Migrate to phoenix 1.7 (#626) 2023-08-15 10:22:18 +00:00
timeline_view.ex Create real Views for all Controllers 2021-05-29 12:15:57 -05:00