mirror of
https://github.com/project-zot/zot.git
synced 2026-06-17 04:48:26 +08:00
feat(startup): update logic for metadb update on startup, skip unmodified repos (#2024)
- MetaDB stores the time of the last update of a repo - During startup we check if the layout has been updated after the last recorded change in the db - If this is the case, the repo is parsed and updated in the DB otherwise it's skipped Signed-off-by: Laurentiu Niculae <niculae.laurentiu1@gmail.com>
This commit is contained in:
@@ -212,7 +212,7 @@ func GenerateRandomName() (string, int64) {
|
||||
return string(randomBytes), seed
|
||||
}
|
||||
|
||||
func AccumulateField[R any, T any](list []T, accFunc func(T) R) []R {
|
||||
func AccumulateField[T any, R any](list []T, accFunc func(T) R) []R {
|
||||
result := make([]R, 0, len(list))
|
||||
|
||||
for i := range list {
|
||||
|
||||
@@ -56,6 +56,15 @@ type MockedImageStore struct {
|
||||
CleanupRepoFn func(repo string, blobs []godigest.Digest, removeRepo bool) (int, error)
|
||||
PutIndexContentFn func(repo string, index ispec.Index) error
|
||||
PopulateStorageMetricsFn func(interval time.Duration, sch *scheduler.Scheduler)
|
||||
StatIndexFn func(repo string) (bool, int64, time.Time, error)
|
||||
}
|
||||
|
||||
func (is MockedImageStore) StatIndex(repo string) (bool, int64, time.Time, error) {
|
||||
if is.StatIndexFn != nil {
|
||||
return is.StatIndexFn(repo)
|
||||
}
|
||||
|
||||
return true, 0, time.Time{}, nil
|
||||
}
|
||||
|
||||
func (is MockedImageStore) Lock(t *time.Time) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package mocks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
godigest "github.com/opencontainers/go-digest"
|
||||
|
||||
@@ -9,6 +10,10 @@ import (
|
||||
)
|
||||
|
||||
type MetaDBMock struct {
|
||||
DeleteRepoMetaFn func(repo string) error
|
||||
|
||||
GetRepoLastUpdatedFn func(repo string) time.Time
|
||||
|
||||
GetStarredReposFn func(ctx context.Context) ([]string, error)
|
||||
|
||||
GetBookmarkedReposFn func(ctx context.Context) ([]string, error)
|
||||
@@ -98,9 +103,35 @@ type MetaDBMock struct {
|
||||
|
||||
ResetRepoReferencesFn func(repo string) error
|
||||
|
||||
GetAllRepoNamesFn func() ([]string, error)
|
||||
|
||||
ResetDBFn func() error
|
||||
}
|
||||
|
||||
func (sdm MetaDBMock) DeleteRepoMeta(repo string) error {
|
||||
if sdm.DeleteRepoMetaFn != nil {
|
||||
return sdm.DeleteRepoMetaFn(repo)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (sdm MetaDBMock) GetAllRepoNames() ([]string, error) {
|
||||
if sdm.GetAllRepoNamesFn != nil {
|
||||
return sdm.GetAllRepoNamesFn()
|
||||
}
|
||||
|
||||
return []string{}, nil
|
||||
}
|
||||
|
||||
func (sdm MetaDBMock) GetRepoLastUpdated(repo string) time.Time {
|
||||
if sdm.GetRepoLastUpdatedFn != nil {
|
||||
return sdm.GetRepoLastUpdatedFn(repo)
|
||||
}
|
||||
|
||||
return time.Time{}
|
||||
}
|
||||
|
||||
func (sdm MetaDBMock) ResetDB() error {
|
||||
if sdm.ResetDBFn != nil {
|
||||
return sdm.ResetDBFn()
|
||||
|
||||
Reference in New Issue
Block a user