stash/pkg/models/mocks/database.go
Abdu Dihan 52bd9392fb
Fix stale browser-cached thumbnails after file content changes during scan. (#6622)
* Fix stale thumbnails after file content changes

When a file's content changed (e.g. after renaming files in a gallery),
the scan handler updated fingerprints but did not bump the entity's
updated_at timestamp. Since thumbnail URLs use updated_at as a cache
buster and are served with immutable/1-year cache headers, browsers
would indefinitely serve the old cached thumbnail.

Update image, scene, and gallery scan handlers to call UpdatePartial
(which sets updated_at to now) whenever file content changes, not only
when a new file association is created.
2026-03-02 15:53:02 +11:00

119 lines
3.2 KiB
Go

// Package mocks provides mocks for various interfaces in [models].
package mocks
import (
"context"
"errors"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/txn"
"github.com/stretchr/testify/mock"
)
type Database struct {
File *FileReaderWriter
Folder *FolderReaderWriter
Gallery *GalleryReaderWriter
GalleryChapter *GalleryChapterReaderWriter
Image *ImageReaderWriter
Group *GroupReaderWriter
Performer *PerformerReaderWriter
Scene *SceneReaderWriter
SceneMarker *SceneMarkerReaderWriter
Studio *StudioReaderWriter
Tag *TagReaderWriter
SavedFilter *SavedFilterReaderWriter
}
func (*Database) Begin(ctx context.Context, exclusive bool) (context.Context, error) {
return ctx, nil
}
func (*Database) WithDatabase(ctx context.Context) (context.Context, error) {
return ctx, nil
}
func (*Database) Commit(ctx context.Context) error {
return nil
}
func (*Database) Rollback(ctx context.Context) error {
return nil
}
func (*Database) Complete(ctx context.Context) {
}
func (*Database) AddPostCommitHook(ctx context.Context, hook txn.TxnFunc) {
}
func (*Database) AddPostRollbackHook(ctx context.Context, hook txn.TxnFunc) {
}
func (*Database) IsLocked(err error) bool {
return false
}
func (*Database) Reset() error {
return nil
}
func NewDatabase() *Database {
return &Database{
File: &FileReaderWriter{},
Folder: &FolderReaderWriter{},
Gallery: &GalleryReaderWriter{},
GalleryChapter: &GalleryChapterReaderWriter{},
Image: &ImageReaderWriter{},
Group: &GroupReaderWriter{},
Performer: &PerformerReaderWriter{},
Scene: &SceneReaderWriter{},
SceneMarker: &SceneMarkerReaderWriter{},
Studio: &StudioReaderWriter{},
Tag: &TagReaderWriter{},
SavedFilter: &SavedFilterReaderWriter{},
}
}
func (db *Database) AssertExpectations(t mock.TestingT) {
db.File.AssertExpectations(t)
db.Folder.AssertExpectations(t)
db.Gallery.AssertExpectations(t)
db.GalleryChapter.AssertExpectations(t)
db.Image.AssertExpectations(t)
db.Group.AssertExpectations(t)
db.Performer.AssertExpectations(t)
db.Scene.AssertExpectations(t)
db.SceneMarker.AssertExpectations(t)
db.Studio.AssertExpectations(t)
db.Tag.AssertExpectations(t)
db.SavedFilter.AssertExpectations(t)
}
// WithTxnCtx runs fn with a context that has a transaction hook manager registered,
// so code that calls txn.AddPostCommitHook (e.g. plugin cache) won't nil-panic.
// Always rolls back to avoid executing the registered hooks.
func (db *Database) WithTxnCtx(fn func(ctx context.Context)) {
_ = txn.WithTxn(context.Background(), db, func(ctx context.Context) error {
fn(ctx)
return errors.New("rollback")
})
}
func (db *Database) Repository() models.Repository {
return models.Repository{
TxnManager: db,
File: db.File,
Folder: db.Folder,
Gallery: db.Gallery,
GalleryChapter: db.GalleryChapter,
Image: db.Image,
Group: db.Group,
Performer: db.Performer,
Scene: db.Scene,
SceneMarker: db.SceneMarker,
Studio: db.Studio,
Tag: db.Tag,
SavedFilter: db.SavedFilter,
}
}