From 1cc09a33f69c9a2820a6f9181ebc6dd12475e389 Mon Sep 17 00:00:00 2001 From: Umputun Date: Fri, 25 Jan 2019 17:35:38 -0600 Subject: [PATCH] fix lack of counter invalidation from the cache #261 --- backend/app/rest/api/admin_test.go | 2 ++ backend/app/rest/api/rest_private.go | 2 +- backend/app/rest/api/rest_public_test.go | 2 ++ backend/app/rest/api/rest_test.go | 5 ++++- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/backend/app/rest/api/admin_test.go b/backend/app/rest/api/admin_test.go index 8f79d6e3..c67b74bc 100644 --- a/backend/app/rest/api/admin_test.go +++ b/backend/app/rest/api/admin_test.go @@ -16,6 +16,7 @@ import ( jwt "github.com/dgrijalva/jwt-go" "github.com/go-pkgz/auth/token" R "github.com/go-pkgz/rest" + "github.com/go-pkgz/rest/cache" "github.com/umputun/remark/backend/app/store/service" "github.com/stretchr/testify/assert" @@ -312,6 +313,7 @@ func TestAdmin_Block(t *testing.T) { assert.Equal(t, "", comments.Comments[0].Text) assert.True(t, comments.Comments[0].Deleted) + srv.Cache = &cache.Nop{} // TODO: with lru cache it won't be refreshed and invalidated for long time time.Sleep(50 * time.Millisecond) res, code = get(t, ts.URL+"/api/v1/find?site=radio-t&url=https://radio-t.com/blah&sort=+time") assert.Equal(t, 200, code) diff --git a/backend/app/rest/api/rest_private.go b/backend/app/rest/api/rest_private.go index f6b07ea0..132b60ba 100644 --- a/backend/app/rest/api/rest_private.go +++ b/backend/app/rest/api/rest_private.go @@ -134,7 +134,7 @@ func (s *Rest) updateCommentCtrl(w http.ResponseWriter, r *http.Request) { return } - s.Cache.Flush(cache.Flusher(locator.SiteID).Scopes(locator.URL, lastCommentsScope, user.ID)) + s.Cache.Flush(cache.Flusher(locator.SiteID).Scopes(locator.SiteID, locator.URL, lastCommentsScope, user.ID)) render.JSON(w, r, res) } diff --git a/backend/app/rest/api/rest_public_test.go b/backend/app/rest/api/rest_public_test.go index 48760bdc..7d8b2d97 100644 --- a/backend/app/rest/api/rest_public_test.go +++ b/backend/app/rest/api/rest_public_test.go @@ -10,6 +10,7 @@ import ( "time" R "github.com/go-pkgz/rest" + "github.com/go-pkgz/rest/cache" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -227,6 +228,7 @@ func TestRest_Last(t *testing.T) { err = srv.DataService.Delete(store.Locator{SiteID: "radio-t", URL: "https://radio-t.com/blah1"}, id1, store.SoftDelete) assert.Nil(t, err) + srv.Cache.Flush(cache.FlusherRequest{}) res, code = get(t, ts.URL+"/api/v1/last/5?site=radio-t") assert.Equal(t, 200, code) err = json.Unmarshal([]byte(res), &comments) diff --git a/backend/app/rest/api/rest_test.go b/backend/app/rest/api/rest_test.go index 1de25da4..26516247 100644 --- a/backend/app/rest/api/rest_test.go +++ b/backend/app/rest/api/rest_test.go @@ -179,6 +179,9 @@ func startupT(t *testing.T) (ts *httptest.Server, srv *Rest, teardown func()) { b, err := engine.NewBoltDB(bolt.Options{}, engine.BoltSite{FileName: testDb, SiteID: "radio-t"}) require.Nil(t, err) + memCache, err := cache.NewMemoryCache() + assert.NoError(t, err) + adminStore := adminstore.NewStaticStore("123456", []string{"a1", "a2"}, "admin@remark-42.com") restrictedWordsMatcher := service.NewRestrictedWordsMatcher(service.StaticRestrictedWordsLister{Words: []string{"duck"}}) @@ -198,7 +201,7 @@ func startupT(t *testing.T) (ts *httptest.Server, srv *Rest, teardown func()) { SecretReader: token.SecretFunc(func() (string, error) { return "secret", nil }), AvatarStore: avatar.NewLocalFS("/tmp/ava-remark42"), }), - Cache: &cache.Nop{}, + Cache: memCache, WebRoot: "/tmp", RemarkURL: "https://demo.remark42.com",