diff --git a/postsDb.go b/postsDb.go index c71a355..6f111e2 100644 --- a/postsDb.go +++ b/postsDb.go @@ -157,6 +157,7 @@ func (a *goBlog) createOrReplacePost(p *post, o *postCreationOptions) error { } // Purge cache a.cache.purge() + a.deleteReactionsCache(p.Path) return nil } @@ -236,6 +237,7 @@ func (a *goBlog) deletePost(path string) error { a.db.rebuildFTSIndex() // Purge cache a.cache.purge() + a.deleteReactionsCache(p.Path) } else { // Update post status p.Status = postStatus(string(p.Status) + statusDeletedSuffix) diff --git a/reactions.go b/reactions.go index ca1fb68..61b2b6c 100644 --- a/reactions.go +++ b/reactions.go @@ -33,6 +33,9 @@ func (a *goBlog) reactionsEnabledForPost(post *post) bool { func (a *goBlog) initReactions() { a.reactionsInit.Do(func() { + if !a.reactionsEnabled() { + return + } a.reactionsCache, _ = ristretto.NewCache(&ristretto.Config{ NumCounters: 1000, MaxCost: 100, // Cache reactions for 100 posts @@ -42,6 +45,13 @@ func (a *goBlog) initReactions() { }) } +func (a *goBlog) deleteReactionsCache(path string) { + a.initReactions() + if a.reactionsCache != nil { + a.reactionsCache.Del(path) + } +} + func (a *goBlog) postReaction(w http.ResponseWriter, r *http.Request) { path := r.FormValue("path") reaction := r.FormValue("reaction")