[chore] renames the GTS caches to DB caches (#3127)

* renames the `GTS` caches to `DB` caches, as it better references what they are

* change remaining Caches.GTS uses to Caches.DB
This commit is contained in:
kim 2024-07-24 09:41:43 +01:00 committed by GitHub
commit 63fc9b6c3e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
39 changed files with 376 additions and 378 deletions

View file

@ -78,7 +78,7 @@ func (r *relationshipDB) GetFollowRequest(ctx context.Context, sourceAccountID s
func (r *relationshipDB) GetFollowRequestsByIDs(ctx context.Context, ids []string) ([]*gtsmodel.FollowRequest, error) {
// Load all follow IDs via cache loader callbacks.
follows, err := r.state.Caches.GTS.FollowRequest.LoadIDs("ID",
follows, err := r.state.Caches.DB.FollowRequest.LoadIDs("ID",
ids,
func(uncached []string) ([]*gtsmodel.FollowRequest, error) {
// Preallocate expected length of uncached followReqs.
@ -137,7 +137,7 @@ func (r *relationshipDB) IsFollowRequested(ctx context.Context, sourceAccountID
func (r *relationshipDB) getFollowRequest(ctx context.Context, lookup string, dbQuery func(*gtsmodel.FollowRequest) error, keyParts ...any) (*gtsmodel.FollowRequest, error) {
// Fetch follow request from database cache with loader callback
followReq, err := r.state.Caches.GTS.FollowRequest.LoadOne(lookup, func() (*gtsmodel.FollowRequest, error) {
followReq, err := r.state.Caches.DB.FollowRequest.LoadOne(lookup, func() (*gtsmodel.FollowRequest, error) {
var followReq gtsmodel.FollowRequest
// Not cached! Perform database query
@ -196,7 +196,7 @@ func (r *relationshipDB) PopulateFollowRequest(ctx context.Context, follow *gtsm
}
func (r *relationshipDB) PutFollowRequest(ctx context.Context, follow *gtsmodel.FollowRequest) error {
return r.state.Caches.GTS.FollowRequest.Store(follow, func() error {
return r.state.Caches.DB.FollowRequest.Store(follow, func() error {
_, err := r.db.NewInsert().Model(follow).Exec(ctx)
return err
})
@ -209,7 +209,7 @@ func (r *relationshipDB) UpdateFollowRequest(ctx context.Context, followRequest
columns = append(columns, "updated_at")
}
return r.state.Caches.GTS.FollowRequest.Store(followRequest, func() error {
return r.state.Caches.DB.FollowRequest.Store(followRequest, func() error {
if _, err := r.db.NewUpdate().
Model(followRequest).
Where("? = ?", bun.Ident("follow_request.id"), followRequest.ID).
@ -242,7 +242,7 @@ func (r *relationshipDB) AcceptFollowRequest(ctx context.Context, sourceAccountI
Notify: followReq.Notify,
}
if err := r.state.Caches.GTS.Follow.Store(follow, func() error {
if err := r.state.Caches.DB.Follow.Store(follow, func() error {
// If the follow already exists, just
// replace the URI with the new one.
_, err := r.db.
@ -304,7 +304,7 @@ func (r *relationshipDB) DeleteFollowRequest(ctx context.Context, sourceAccountI
}
// Drop this now-cached follow request on return after delete.
defer r.state.Caches.GTS.FollowRequest.Invalidate("AccountID,TargetAccountID", sourceAccountID, targetAccountID)
defer r.state.Caches.DB.FollowRequest.Invalidate("AccountID,TargetAccountID", sourceAccountID, targetAccountID)
// Finally delete followreq from DB.
_, err = r.db.NewDelete().
@ -328,7 +328,7 @@ func (r *relationshipDB) DeleteFollowRequestByID(ctx context.Context, id string)
}
// Drop this now-cached follow request on return after delete.
defer r.state.Caches.GTS.FollowRequest.Invalidate("ID", id)
defer r.state.Caches.DB.FollowRequest.Invalidate("ID", id)
// Finally delete followreq from DB.
_, err = r.db.NewDelete().
@ -352,7 +352,7 @@ func (r *relationshipDB) DeleteFollowRequestByURI(ctx context.Context, uri strin
}
// Drop this now-cached follow request on return after delete.
defer r.state.Caches.GTS.FollowRequest.Invalidate("URI", uri)
defer r.state.Caches.DB.FollowRequest.Invalidate("URI", uri)
// Finally delete followreq from DB.
_, err = r.db.NewDelete().
@ -382,8 +382,8 @@ func (r *relationshipDB) DeleteAccountFollowRequests(ctx context.Context, accoun
defer func() {
// Invalidate all account's incoming / outoing follow requests on return.
r.state.Caches.GTS.FollowRequest.Invalidate("AccountID", accountID)
r.state.Caches.GTS.FollowRequest.Invalidate("TargetAccountID", accountID)
r.state.Caches.DB.FollowRequest.Invalidate("AccountID", accountID)
r.state.Caches.DB.FollowRequest.Invalidate("TargetAccountID", accountID)
}()
// Load all followreqs into cache, this *really* isn't