mirror of
https://github.com/stashapp/stash.git
synced 2026-05-09 05:05:29 +02:00
* Bump go version in go.mod * Update compiler image. Changed github download url since existing one didn't have version 12 of the SDK. * Update macOS requirements in README for v0.32.0 * Update lint action * Bump golangci-lint version * Migrate golangci-lint config * Fix QF1012 errors (Use fmt.Fprintf(...) instead of WriteString(fmt.Sprintf(...))) * Fix QF1003 errors (could use tagged switch) * Fix ST1005 errors (error string capitalisation) * Fix ST1011 errors (seconds suffix) * Fix QF1006 errors (lift into loop condition) * Fix QF1002 errors (switch condition) * Fix gocritic error (deprecated paragraph) * Fix incorrect nolint directive * Ignore specific checks noctx should be addressed in a later PR --------- Co-authored-by: DogmaDragon <103123951+DogmaDragon@users.noreply.github.com> Co-authored-by: feederbox826 <me@feederbox.cc>
56 lines
1.1 KiB
Go
56 lines
1.1 KiB
Go
package manager
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/stashapp/stash/pkg/job"
|
|
"github.com/stashapp/stash/pkg/logger"
|
|
)
|
|
|
|
type Optimiser interface {
|
|
Analyze(ctx context.Context) error
|
|
Vacuum(ctx context.Context) error
|
|
}
|
|
|
|
type OptimiseDatabaseJob struct {
|
|
Optimiser Optimiser
|
|
}
|
|
|
|
func (j *OptimiseDatabaseJob) Execute(ctx context.Context, progress *job.Progress) error {
|
|
logger.Info("Optimising database")
|
|
progress.SetTotal(2)
|
|
|
|
start := time.Now()
|
|
|
|
var err error
|
|
|
|
progress.ExecuteTask("Analyzing database", func() {
|
|
err = j.Optimiser.Analyze(ctx)
|
|
progress.Increment()
|
|
})
|
|
if job.IsCancelled(ctx) {
|
|
logger.Info("Stopping due to user request")
|
|
return nil
|
|
}
|
|
if err != nil {
|
|
return fmt.Errorf("error analyzing database: %w", err)
|
|
}
|
|
|
|
progress.ExecuteTask("Vacuuming database", func() {
|
|
err = j.Optimiser.Vacuum(ctx)
|
|
progress.Increment()
|
|
})
|
|
if job.IsCancelled(ctx) {
|
|
logger.Info("Stopping due to user request")
|
|
return nil
|
|
}
|
|
if err != nil {
|
|
return fmt.Errorf("error vacuuming database: %w", err)
|
|
}
|
|
|
|
elapsed := time.Since(start)
|
|
logger.Infof("Finished optimising database after %s", elapsed)
|
|
return nil
|
|
}
|