Fix gallery checksum resolver error (#2929)

This commit is contained in:
WithoutPants 2022-09-19 16:50:04 +10:00 committed by GitHub
parent 8efbcc1c4d
commit 98e3610ade
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 20 additions and 7 deletions

View file

@ -177,6 +177,18 @@ func (r *galleryResolver) Date(ctx context.Context, obj *models.Gallery) (*strin
return nil, nil
}
func (r *galleryResolver) Checksum(ctx context.Context, obj *models.Gallery) (string, error) {
if !obj.Files.PrimaryLoaded() {
if err := r.withTxn(ctx, func(ctx context.Context) error {
return obj.LoadPrimaryFile(ctx, r.repository.File)
}); err != nil {
return "", err
}
}
return obj.PrimaryChecksum(), nil
}
func (r *galleryResolver) Scenes(ctx context.Context, obj *models.Gallery) (ret []*models.Scene, err error) {
if !obj.SceneIDs.Loaded() {
if err := r.withTxn(ctx, func(ctx context.Context) error {

View file

@ -373,7 +373,7 @@ func (r *mutationResolver) GalleryDestroy(ctx context.Context, input models.Gall
for _, gallery := range galleries {
r.hookExecutor.ExecutePostHooks(ctx, gallery.ID, plugin.GalleryDestroyPost, plugin.GalleryDestroyInput{
GalleryDestroyInput: input,
Checksum: gallery.Checksum(),
Checksum: gallery.PrimaryChecksum(),
Path: gallery.Path,
}, nil)
}

View file

@ -268,7 +268,7 @@ func (h *cleanHandler) handleRelatedGalleries(ctx context.Context, fileID file.I
}
mgr.PluginCache.RegisterPostHooks(ctx, g.ID, plugin.GalleryDestroyPost, plugin.GalleryDestroyInput{
Checksum: g.Checksum(),
Checksum: g.PrimaryChecksum(),
Path: g.Path,
}, nil)
} else {

View file

@ -335,7 +335,7 @@ func (t *ExportTask) populateGalleryImages(ctx context.Context, repo Repository)
images, err := imageReader.FindByGalleryID(ctx, g.ID)
if err != nil {
logger.Errorf("[galleries] <%s> failed to fetch images for gallery: %s", g.Checksum(), err.Error())
logger.Errorf("[galleries] <%s> failed to fetch images for gallery: %s", g.PrimaryChecksum(), err.Error())
continue
}
@ -765,7 +765,7 @@ func exportGallery(ctx context.Context, wg *sync.WaitGroup, jobChan <-chan *mode
continue
}
galleryHash := g.Checksum()
galleryHash := g.PrimaryChecksum()
newGalleryJSON, err := gallery.ToBasicJSON(g)
if err != nil {

View file

@ -78,7 +78,8 @@ func (g *Gallery) LoadTagIDs(ctx context.Context, l TagIDLoader) error {
})
}
func (g Gallery) Checksum() string {
func (g Gallery) PrimaryChecksum() string {
// renamed from Checksum to prevent gqlgen from using it in the resolver
if p := g.Files.Primary(); p != nil {
v := p.Base().Fingerprints.Get(file.FingerprintTypeMD5)
if v == nil {

View file

@ -51,7 +51,7 @@ func queryURLParameterFromURL(url string) queryURLParameters {
func queryURLParametersFromGallery(gallery *models.Gallery) queryURLParameters {
ret := make(queryURLParameters)
ret["checksum"] = gallery.Checksum()
ret["checksum"] = gallery.PrimaryChecksum()
if gallery.Path != "" {
ret["filename"] = filepath.Base(gallery.Path)

View file

@ -282,7 +282,7 @@ func (s *stashScraper) scrapeGalleryByGallery(ctx context.Context, gallery *mode
Checksum *string `graphql:"checksum" json:"checksum"`
}
checksum := gallery.Checksum()
checksum := gallery.PrimaryChecksum()
input := GalleryHashInput{
Checksum: &checksum,
}