diff options
author | 2022-12-10 22:43:11 +0100 | |
---|---|---|
committer | 2022-12-10 21:43:11 +0000 | |
commit | 5e060d0bcb9af77e7b6d11acba99db6219d4f68e (patch) | |
tree | 8dee821f5577ed38be754d73370ed2b74c8f0d2b /internal/media/manager.go | |
parent | [chore] make single pull request template (#1239) (diff) | |
download | gotosocial-5e060d0bcb9af77e7b6d11acba99db6219d4f68e.tar.xz |
[feature] Start implementing refetch of lost media files via `/api/v1/admin/media_refetch` (#1221)
* [chore] Move ShortcodeDomain to its own little util func
* [feature] Add RefetchEmojis function to media manager
* [feature] Expose admin media refresh via admin API
* update following review feedback
- change/fix log levels
- make sure not to try to refetch local emojis
- small style refactoring + comments
* log on emoji refetch start
Signed-off-by: kim <grufwub@gmail.com>
Co-authored-by: kim <grufwub@gmail.com>
Diffstat (limited to 'internal/media/manager.go')
-rw-r--r-- | internal/media/manager.go | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/internal/media/manager.go b/internal/media/manager.go index 67c03fb31..a9d71e589 100644 --- a/internal/media/manager.go +++ b/internal/media/manager.go @@ -40,6 +40,15 @@ const UnusedLocalAttachmentCacheDays = 3 // Manager provides an interface for managing media: parsing, storing, and retrieving media objects like photos, videos, and gifs. type Manager interface { + // Stop stops the underlying worker pool of the manager. It should be called + // when closing GoToSocial in order to cleanly finish any in-progress jobs. + // It will block until workers are finished processing. + Stop() error + + /* + PROCESSING FUNCTIONS + */ + // ProcessMedia begins the process of decoding and storing the given data as an attachment. // It will return a pointer to a ProcessingMedia struct upon which further actions can be performed, such as getting // the finished media, thumbnail, attachment, etc. @@ -75,6 +84,10 @@ type Manager interface { // RecacheMedia refetches, reprocesses, and recaches an existing attachment that has been uncached via pruneRemote. RecacheMedia(ctx context.Context, data DataFunc, postData PostDataCallbackFunc, attachmentID string) (*ProcessingMedia, error) + /* + PRUNING FUNCTIONS + */ + // PruneAllRemote prunes all remote media attachments cached on this instance which are older than the given amount of days. // 'Pruning' in this context means removing the locally stored data of the attachment (both thumbnail and full size), // and setting 'cached' to false on the associated attachment. @@ -98,10 +111,18 @@ type Manager interface { // is returned to the caller. PruneOrphaned(ctx context.Context, dry bool) (int, error) - // Stop stops the underlying worker pool of the manager. It should be called - // when closing GoToSocial in order to cleanly finish any in-progress jobs. - // It will block until workers are finished processing. - Stop() error + /* + REFETCHING FUNCTIONS + Useful when data loss has occurred. + */ + + // RefetchEmojis iterates through remote emojis (for the given domain, or all if domain is empty string). + // + // For each emoji, the manager will check whether both the full size and static images are present in storage. + // If not, the manager will refetch and reprocess full size and static images for the emoji. + // + // The provided DereferenceMedia function will be used when it's necessary to refetch something this way. + RefetchEmojis(ctx context.Context, domain string, dereferenceMedia DereferenceMedia) (int, error) } type manager struct { |