[chore] Add interaction policy gtsmodels (#3075)

* [chore] introduce interaction policy gts models

* update migration a smidge

* fix copy paste typo

* update migration

* use int for InteractionType
This commit is contained in:
tobi 2024-07-11 16:44:29 +02:00 committed by GitHub
commit 5bc567196b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
46 changed files with 1318 additions and 531 deletions

View file

@ -23,6 +23,7 @@ import (
"errors"
"fmt"
"slices"
"time"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtscontext"
@ -77,6 +78,21 @@ func (s *statusFaveDB) GetStatusFaveByID(ctx context.Context, id string) (*gtsmo
)
}
func (s *statusFaveDB) GetStatusFaveByURI(ctx context.Context, uri string) (*gtsmodel.StatusFave, error) {
return s.getStatusFave(
ctx,
"URI",
func(fave *gtsmodel.StatusFave) error {
return s.db.
NewSelect().
Model(fave).
Where("? = ?", bun.Ident("uri"), uri).
Scan(ctx)
},
uri,
)
}
func (s *statusFaveDB) getStatusFave(ctx context.Context, lookup string, dbQuery func(*gtsmodel.StatusFave) error, keyParts ...any) (*gtsmodel.StatusFave, error) {
// Fetch status fave from database cache with loader callback
fave, err := s.state.Caches.GTS.StatusFave.LoadOne(lookup, func() (*gtsmodel.StatusFave, error) {
@ -242,6 +258,26 @@ func (s *statusFaveDB) PutStatusFave(ctx context.Context, fave *gtsmodel.StatusF
})
}
func (s *statusFaveDB) UpdateStatusFave(ctx context.Context, fave *gtsmodel.StatusFave, columns ...string) error {
fave.UpdatedAt = time.Now()
if len(columns) > 0 {
// If we're updating by column,
// ensure "updated_at" is included.
columns = append(columns, "updated_at")
}
// Update the status fave model in the database.
return s.state.Caches.GTS.StatusFave.Store(fave, func() error {
_, err := s.db.
NewUpdate().
Model(fave).
Where("? = ?", bun.Ident("status_fave.id"), fave.ID).
Column(columns...).
Exec(ctx)
return err
})
}
func (s *statusFaveDB) DeleteStatusFaveByID(ctx context.Context, id string) error {
var statusID string