diff options
author | 2024-07-11 16:44:29 +0200 | |
---|---|---|
committer | 2024-07-11 15:44:29 +0100 | |
commit | 5bc567196bf2204272950c525e8592e56057c3bd (patch) | |
tree | 24aec5e75d2a0208505da16ee2c55efd887d3e25 /internal/db/bundb/statusfave.go | |
parent | [bugfix] Don't throw error when parent statuses are missing (#2011) (#3088) (diff) | |
download | gotosocial-5bc567196bf2204272950c525e8592e56057c3bd.tar.xz |
[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
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 |