diff options
Diffstat (limited to 'internal/db/bundb/statusfave.go')
-rw-r--r-- | internal/db/bundb/statusfave.go | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/internal/db/bundb/statusfave.go b/internal/db/bundb/statusfave.go index 8e9ff501c..e3daa876b 100644 --- a/internal/db/bundb/statusfave.go +++ b/internal/db/bundb/statusfave.go @@ -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 |