From bef7a9b3736953e414aa066557571578001c1561 Mon Sep 17 00:00:00 2001 From: gjbae1212 Date: Wed, 19 Feb 2020 10:21:46 +0900 Subject: [PATCH] Update a rule for updating cache. --- git/wrapper.go | 3 ++- git/wrapper_test.go | 4 ++++ search/searcher.go | 3 ++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/git/wrapper.go b/git/wrapper.go index 6775f21..5667dfb 100644 --- a/git/wrapper.go +++ b/git/wrapper.go @@ -39,6 +39,7 @@ type Starred struct { UpdateAt JsonTime `json:"updated_at,omitempty"` PushedAt JsonTime `json:"pushed_at,omitempty"` Readme string `json:"readme,omitempty"` + CachedAt JsonTime `json:"cached_at,omitempty"` Error error `json:"-"` } @@ -143,7 +144,7 @@ func (w *wrapper) ListStarredAll() ([]*Starred, error) { WatchersCount: star.GetRepository().GetWatchersCount(), StargazersCount: star.GetRepository().GetStargazersCount(), ForksCount: star.GetRepository().GetForksCount(), StarredAt: JsonTime{star.GetStarredAt().Time}, CreatedAt: JsonTime{star.GetRepository().GetCreatedAt().Time}, UpdateAt: JsonTime{star.GetRepository().GetUpdatedAt().Time}, - PushedAt: JsonTime{star.GetRepository().GetPushedAt().Time}, + PushedAt: JsonTime{star.GetRepository().GetPushedAt().Time}, CachedAt: JsonTime{time.Now()}, }) } diff --git a/git/wrapper_test.go b/git/wrapper_test.go index 4e470dc..d422f06 100644 --- a/git/wrapper_test.go +++ b/git/wrapper_test.go @@ -53,6 +53,7 @@ func TestModel_MarshalAndUnMarsahlJSON(t *testing.T) { CreatedAt: JsonTime{time.Now()}, UpdateAt: JsonTime{time.Now()}, PushedAt: JsonTime{time.Now()}, + CachedAt: JsonTime{time.Now()}, } starredData, err := json.Marshal(starred) assert.NoError(err) @@ -74,6 +75,7 @@ func TestModel_MarshalAndUnMarsahlJSON(t *testing.T) { assert.Equal(starred.CreatedAt.Unix(), rstarred.CreatedAt.Unix()) assert.Equal(starred.UpdateAt.Unix(), rstarred.UpdateAt.Unix()) assert.Equal(starred.PushedAt.Unix(), rstarred.PushedAt.Unix()) + assert.Equal(starred.CachedAt.Unix(), rstarred.CachedAt.Unix()) // Readme readme := &Readme{ @@ -183,7 +185,9 @@ func TestWrapper_ListStarredAll(t *testing.T) { total := map[string]string{} for _, star := range result { total[star.FullName] = "" + assert.True(time.Now().Add(-1*time.Hour).Unix() < star.CachedAt.Unix()) } + color.Green("Total Starred %d %d", len(result), len(total)) } } diff --git a/search/searcher.go b/search/searcher.go index 53d9dd6..b3a882d 100644 --- a/search/searcher.go +++ b/search/searcher.go @@ -277,7 +277,8 @@ func (s *searcher) CreateIndex() error { color.White("[insert] %s repository pushed_at %s", newStarred.FullName, newStarred.PushedAt.Format(time.RFC3339)) } else { - if oldStarred.PushedAt.Unix() != newStarred.PushedAt.Unix() { + if oldStarred.PushedAt.Unix() != newStarred.PushedAt.Unix() && + oldStarred.CachedAt.Unix() < time.Now().Add(-24*time.Hour).Unix() { updateList = append(updateList, newStarred) color.White("[update] %s repository pushed_at %s", newStarred.FullName, newStarred.PushedAt.Format(time.RFC3339))