Browse Source

Correctly delete reactions cache

master
Jan-Lukas Else 1 month ago
parent
commit
607f8e10f0
  1. 2
      postsDb.go
  2. 10
      reactions.go

2
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)

10
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")

Loading…
Cancel
Save