Correctly delete reactions cache

This commit is contained in:
Jan-Lukas Else 2022-04-17 07:40:02 +02:00
parent 69cbe4ba37
commit 607f8e10f0
2 changed files with 12 additions and 0 deletions

View File

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

View File

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