Documentation
¶
Index ¶
- Variables
- type Dereferencer
- func (d *Dereferencer) DereferenceStatusAncestors(ctx context.Context, username string, status *gtsmodel.Status) error
- func (d *Dereferencer) DereferenceStatusDescendants(ctx context.Context, username string, statusIRI *url.URL, parent ap.Statusable) error
- func (d *Dereferencer) EnrichAnnounce(ctx context.Context, boost *gtsmodel.Status, requestUser string) (*gtsmodel.Status, error)
- func (d *Dereferencer) GetAccountByURI(ctx context.Context, requestUser string, uri *url.URL, tryURL bool) (*gtsmodel.Account, ap.Accountable, error)
- func (d *Dereferencer) GetAccountByUsernameDomain(ctx context.Context, requestUser string, username string, domain string) (*gtsmodel.Account, ap.Accountable, error)
- func (d *Dereferencer) GetEmoji(ctx context.Context, shortcode string, domain string, remoteURL string, ...) (*gtsmodel.Emoji, error)
- func (d *Dereferencer) GetMedia(ctx context.Context, requestUser string, accountID string, remoteURL string, ...) (*gtsmodel.MediaAttachment, error)
- func (d *Dereferencer) GetRemoteInstance(ctx context.Context, username string, remoteInstanceURI *url.URL) (*gtsmodel.Instance, error)
- func (d *Dereferencer) GetStatusByURI(ctx context.Context, requestUser string, uri *url.URL) (*gtsmodel.Status, ap.Statusable, error)
- func (d *Dereferencer) Handshaking(username string, remoteAccountID *url.URL) bool
- func (d *Dereferencer) RecacheEmoji(ctx context.Context, emoji *gtsmodel.Emoji, async bool) (*gtsmodel.Emoji, error)
- func (d *Dereferencer) RefreshAccount(ctx context.Context, requestUser string, account *gtsmodel.Account, ...) (*gtsmodel.Account, ap.Accountable, error)
- func (d *Dereferencer) RefreshAccountAsync(ctx context.Context, requestUser string, account *gtsmodel.Account, ...)
- func (d *Dereferencer) RefreshEmoji(ctx context.Context, emoji *gtsmodel.Emoji, info media.AdditionalEmojiInfo, ...) (*gtsmodel.Emoji, error)
- func (d *Dereferencer) RefreshMedia(ctx context.Context, requestUser string, attach *gtsmodel.MediaAttachment, ...) (*gtsmodel.MediaAttachment, error)
- func (d *Dereferencer) RefreshStatus(ctx context.Context, requestUser string, status *gtsmodel.Status, ...) (*gtsmodel.Status, ap.Statusable, error)
- func (d *Dereferencer) RefreshStatusAsync(ctx context.Context, requestUser string, status *gtsmodel.Status, ...)
- type FreshnessWindow
Constants ¶
This section is empty.
Variables ¶
var ( // 6 hours. // // Default window for doing a // fresh dereference of an Account. DefaultAccountFreshness = util.Ptr(FreshnessWindow(6 * time.Hour)) // 2 hours. // // Default window for doing a // fresh dereference of a Status. DefaultStatusFreshness = util.Ptr(FreshnessWindow(2 * time.Hour)) // 5 minutes. // // Fresh is useful when you're wanting // a more up-to-date model of something // that exceeds default freshness windows. // // This is tuned to be quite fresh without // causing loads of dereferencing calls. Fresh = util.Ptr(FreshnessWindow(5 * time.Minute)) // 5 seconds. // // Freshest is useful when you want an // immediately up to date model of something // that's even fresher than Fresh. // // Be careful using this one; it can cause // lots of unnecessary traffic if used unwisely. Freshest = util.Ptr(FreshnessWindow(5 * time.Second)) )
Functions ¶
This section is empty.
Types ¶
type Dereferencer ¶
type Dereferencer struct {
// contains filtered or unexported fields
}
Dereferencer wraps logic and functionality for doing dereferencing of remote accounts, statuses, etc, from federated instances.
func NewDereferencer ¶
func NewDereferencer( state *state.State, converter *typeutils.Converter, transportController transport.Controller, visFilter *visibility.Filter, intFilter *interaction.Filter, mediaManager *media.Manager, ) Dereferencer
NewDereferencer returns a Dereferencer initialized with the given parameters.
func (*Dereferencer) DereferenceStatusAncestors ¶
func (d *Dereferencer) DereferenceStatusAncestors(ctx context.Context, username string, status *gtsmodel.Status) error
DereferenceStatusAncestors iterates upwards from the given status, using InReplyToURI, to ensure that as many parent statuses as possible are dereferenced.
func (*Dereferencer) DereferenceStatusDescendants ¶
func (d *Dereferencer) DereferenceStatusDescendants(ctx context.Context, username string, statusIRI *url.URL, parent ap.Statusable) error
DereferenceStatusDescendents iterates downwards from the given status, using its replies, to ensure that as many children statuses as possible are dereferenced.
func (*Dereferencer) EnrichAnnounce ¶
func (d *Dereferencer) EnrichAnnounce( ctx context.Context, boost *gtsmodel.Status, requestUser string, ) (*gtsmodel.Status, error)
EnrichAnnounce enriches the given boost wrapper status by either fetching from the DB or dereferencing the target status, populating the boost wrapper's fields based on the target status, and then storing the wrapper in the database. The wrapper is then returned to the caller.
The provided boost wrapper status must have BoostOfURI set.
func (*Dereferencer) GetAccountByURI ¶
func (d *Dereferencer) GetAccountByURI( ctx context.Context, requestUser string, uri *url.URL, tryURL bool, ) (*gtsmodel.Account, ap.Accountable, error)
GetAccountByURI will attempt to fetch an accounts by its URI, first checking the database. In the case of a newly-met remote model, or a remote model whose last_fetched date is beyond a certain interval, the account will be dereferenced. In the case of dereferencing, some low-priority account info may be enqueued for asynchronous fetching, e.g. pinned statuses. An ActivityPub object indicates the account was dereferenced.
if tryURL is true, then the database will also check for a *single* account where uri == account.url, not just uri == account.uri. Because url does not guarantee uniqueness, you should only set tryURL to true when doing searches set in motion by a user, ie., when it's not important that an exact account is returned.
func (*Dereferencer) GetAccountByUsernameDomain ¶
func (d *Dereferencer) GetAccountByUsernameDomain(ctx context.Context, requestUser string, username string, domain string) (*gtsmodel.Account, ap.Accountable, error)
GetAccountByUsernameDomain will attempt to fetch an accounts by its username@domain, first checking the database. In the case of a newly-met remote model, or a remote model whose last_fetched date is beyond a certain interval, the account will be dereferenced. In the case of dereferencing, some low-priority account information may be enqueued for asynchronous fetching, e.g. featured account statuses (pins). An ActivityPub object indicates the account was dereferenced.
func (*Dereferencer) GetEmoji ¶
func (d *Dereferencer) GetEmoji( ctx context.Context, shortcode string, domain string, remoteURL string, info media.AdditionalEmojiInfo, refresh bool, async bool, ) ( *gtsmodel.Emoji, error, )
GetEmoji fetches the emoji with given shortcode, domain and remote URL to dereference it by. This handles the case of existing emojis by passing them to RefreshEmoji(), which in the case of a local emoji will be a no-op. If the emoji does not yet exist it will be newly inserted into the database followed by dereferencing the actual media file.
Please note that even if an error is returned, an emoji model may still be returned if the error was only encountered during actual dereferencing. In this case, it will act as a placeholder.
func (*Dereferencer) GetMedia ¶
func (d *Dereferencer) GetMedia( ctx context.Context, requestUser string, accountID string, remoteURL string, info media.AdditionalMediaInfo, ) ( *gtsmodel.MediaAttachment, error, )
GetMedia fetches the media at given remote URL by dereferencing it. The passed accountID is used to store it as being owned by that account. Additional information to set on the media attachment may also be provided.
Please note that even if an error is returned, a media model may still be returned if the error was only encountered during actual dereferencing. In this case, it will act as a placeholder.
Also note that since account / status dereferencing is already protected by per-uri locks, and that fediverse media is generally not shared between accounts (etc), there aren't any concurrency protections against multiple insertion / dereferencing of media at remoteURL. Worst case scenario, an extra media entry will be inserted and the scheduled cleaner.Cleaner{} will catch it!
func (*Dereferencer) GetRemoteInstance ¶
func (*Dereferencer) GetStatusByURI ¶
func (d *Dereferencer) GetStatusByURI(ctx context.Context, requestUser string, uri *url.URL) (*gtsmodel.Status, ap.Statusable, error)
GetStatusByURI will attempt to fetch a status by its URI, first checking the database. In the case of a newly-met remote model, or a remote model whose 'last_fetched' date is beyond a certain interval, the status will be dereferenced. In the case of dereferencing, some low-priority status information may be enqueued for asynchronous fetching, e.g. dereferencing the status thread. An ActivityPub object indicates the status was dereferenced.
func (*Dereferencer) Handshaking ¶
func (d *Dereferencer) Handshaking(username string, remoteAccountID *url.URL) bool
func (*Dereferencer) RecacheEmoji ¶
func (d *Dereferencer) RecacheEmoji( ctx context.Context, emoji *gtsmodel.Emoji, async bool, ) ( *gtsmodel.Emoji, error, )
RecacheEmoji handles the simplest case which is that of an existing emoji that only needs to be recached. It handles the case of both local emojis, and those already cached as no-ops.
Please note that even if an error is returned, an emoji model may still be returned if the error was only encountered during actual dereferencing. In this case, it will act as a placeholder.
func (*Dereferencer) RefreshAccount ¶
func (d *Dereferencer) RefreshAccount( ctx context.Context, requestUser string, account *gtsmodel.Account, accountable ap.Accountable, window *FreshnessWindow, ) (*gtsmodel.Account, ap.Accountable, error)
RefreshAccount updates the given account if it's a remote account, and considered stale / not fresh based on Account.FetchedAt and desired freshness.
An updated account model is returned, but in the case of dereferencing, some low-priority account info may be enqueued for asynchronous fetching, e.g. featured account statuses (pins).
An ActivityPub object indicates the account was dereferenced (i.e. updated).
func (*Dereferencer) RefreshAccountAsync ¶
func (d *Dereferencer) RefreshAccountAsync( ctx context.Context, requestUser string, account *gtsmodel.Account, accountable ap.Accountable, window *FreshnessWindow, )
RefreshAccountAsync enqueues the given account for an asychronous update fetching, if it's a remote account, and considered stale / not fresh based on Account.FetchedAt and desired freshness.
This is a more optimized form of manually enqueueing .UpdateAccount() to the federation worker, since it only enqueues update if necessary.
func (*Dereferencer) RefreshEmoji ¶
func (d *Dereferencer) RefreshEmoji( ctx context.Context, emoji *gtsmodel.Emoji, info media.AdditionalEmojiInfo, force bool, async bool, ) ( *gtsmodel.Emoji, error, )
RefreshEmoji ensures that the given emoji is up-to-date, both in terms of being cached in in local instance storage, and compared to extra information provided in media.AdditionEmojiInfo{}. (note that is a no-op to pass in a local emoji).
Please note that even if an error is returned, an emoji model may still be returned if the error was only encountered during actual dereferencing. In this case, it will act as a placeholder.
func (*Dereferencer) RefreshMedia ¶
func (d *Dereferencer) RefreshMedia( ctx context.Context, requestUser string, attach *gtsmodel.MediaAttachment, info media.AdditionalMediaInfo, force bool, ) ( *gtsmodel.MediaAttachment, error, )
RefreshMedia ensures that given media is up-to-date, both in terms of being cached in local instance, storage and compared to extra info in information in given gtsmodel.AdditionMediaInfo{}. This handles the case of local emoji by returning early.
Please note that even if an error is returned, a media model may still be returned if the error was only encountered during actual dereferencing. In this case, it will act as a placeholder.
Also note that since account / status dereferencing is already protected by per-uri locks, and that fediverse media is generally not shared between accounts (etc), there aren't any concurrency protections against multiple insertion / dereferencing of media at remoteURL. Worst case scenario, an extra media entry will be inserted and the scheduled cleaner.Cleaner{} will catch it!
func (*Dereferencer) RefreshStatus ¶
func (d *Dereferencer) RefreshStatus( ctx context.Context, requestUser string, status *gtsmodel.Status, statusable ap.Statusable, window *FreshnessWindow, ) (*gtsmodel.Status, ap.Statusable, error)
RefreshStatus is functionally equivalent to GetStatusByURI(), except that it requires a pre populated status model (with AT LEAST uri set), and ALL thread dereferencing is asynchronous.
func (*Dereferencer) RefreshStatusAsync ¶
func (d *Dereferencer) RefreshStatusAsync( ctx context.Context, requestUser string, status *gtsmodel.Status, statusable ap.Statusable, window *FreshnessWindow, )
RefreshStatusAsync is functionally equivalent to RefreshStatus(), except that ALL dereferencing is queued for asynchronous processing, (both thread AND status).
type FreshnessWindow ¶
FreshnessWindow represents a duration in which a Status or Account is still considered to be "fresh" (ie., not in need of a refresh from remote), if its last FetchedAt value falls within the window.
For example, if an Account was FetchedAt 09:00, and it is now 12:00, then it would be considered "fresh" according to DefaultAccountFreshness, but not according to Fresh, which would indicate that the Account requires refreshing from remote.