From 527317da65bf942e4758fec65a06ecae6999ae2b Mon Sep 17 00:00:00 2001 From: DmitriyLewen Date: Wed, 25 Sep 2024 16:23:57 +0600 Subject: [PATCH 1/2] fix(java-db): check `DownloadedAt` --- pkg/javadb/client.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/pkg/javadb/client.go b/pkg/javadb/client.go index ca055a0c333f..d025614e577e 100644 --- a/pkg/javadb/client.go +++ b/pkg/javadb/client.go @@ -53,7 +53,7 @@ func (u *Updater) Update() error { } } - if (meta.Version != SchemaVersion || meta.NextUpdate.Before(time.Now().UTC())) && !u.skip { + if (meta.Version != SchemaVersion || !u.isNewDB(meta)) && !u.skip { // Download DB log.Info("Java DB Repository", log.Any("repository", u.repo)) log.Info("Downloading the Java DB...") @@ -85,6 +85,20 @@ func (u *Updater) Update() error { return nil } +func (u *Updater) isNewDB(meta db.Metadata) bool { + now := time.Now().UTC() + if now.Before(meta.NextUpdate) { + log.Debug("Java DB update was skipped because the local Java DB is the latest") + return true + } + + if now.Before(meta.DownloadedAt.Add(time.Hour * 24)) { // 1 day + log.Debug("Java DB update was skipped because the local Java DB was downloaded during the last hour") + return true + } + return false +} + func Init(cacheDir string, javaDBRepository name.Reference, skip, quiet bool, registryOption ftypes.RegistryOptions) { updater = &Updater{ repo: javaDBRepository, From 1de0a8177759c428dc7e371d9b467c310eb00dc8 Mon Sep 17 00:00:00 2001 From: DmitriyLewen Date: Thu, 26 Sep 2024 11:04:23 +0600 Subject: [PATCH 2/2] refactor: update log --- pkg/javadb/client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/javadb/client.go b/pkg/javadb/client.go index d025614e577e..936c2d40c028 100644 --- a/pkg/javadb/client.go +++ b/pkg/javadb/client.go @@ -93,7 +93,7 @@ func (u *Updater) isNewDB(meta db.Metadata) bool { } if now.Before(meta.DownloadedAt.Add(time.Hour * 24)) { // 1 day - log.Debug("Java DB update was skipped because the local Java DB was downloaded during the last hour") + log.Debug("Java DB update was skipped because the local Java DB was downloaded during the last day") return true } return false