mirror of https://github.com/jlelse/GoBlog
Correctly delete reactions cache
This commit is contained in:
parent
69cbe4ba37
commit
607f8e10f0
|
@ -157,6 +157,7 @@ func (a *goBlog) createOrReplacePost(p *post, o *postCreationOptions) error {
|
||||||
}
|
}
|
||||||
// Purge cache
|
// Purge cache
|
||||||
a.cache.purge()
|
a.cache.purge()
|
||||||
|
a.deleteReactionsCache(p.Path)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,6 +237,7 @@ func (a *goBlog) deletePost(path string) error {
|
||||||
a.db.rebuildFTSIndex()
|
a.db.rebuildFTSIndex()
|
||||||
// Purge cache
|
// Purge cache
|
||||||
a.cache.purge()
|
a.cache.purge()
|
||||||
|
a.deleteReactionsCache(p.Path)
|
||||||
} else {
|
} else {
|
||||||
// Update post status
|
// Update post status
|
||||||
p.Status = postStatus(string(p.Status) + statusDeletedSuffix)
|
p.Status = postStatus(string(p.Status) + statusDeletedSuffix)
|
||||||
|
|
10
reactions.go
10
reactions.go
|
@ -33,6 +33,9 @@ func (a *goBlog) reactionsEnabledForPost(post *post) bool {
|
||||||
|
|
||||||
func (a *goBlog) initReactions() {
|
func (a *goBlog) initReactions() {
|
||||||
a.reactionsInit.Do(func() {
|
a.reactionsInit.Do(func() {
|
||||||
|
if !a.reactionsEnabled() {
|
||||||
|
return
|
||||||
|
}
|
||||||
a.reactionsCache, _ = ristretto.NewCache(&ristretto.Config{
|
a.reactionsCache, _ = ristretto.NewCache(&ristretto.Config{
|
||||||
NumCounters: 1000,
|
NumCounters: 1000,
|
||||||
MaxCost: 100, // Cache reactions for 100 posts
|
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) {
|
func (a *goBlog) postReaction(w http.ResponseWriter, r *http.Request) {
|
||||||
path := r.FormValue("path")
|
path := r.FormValue("path")
|
||||||
reaction := r.FormValue("reaction")
|
reaction := r.FormValue("reaction")
|
||||||
|
|
Loading…
Reference in New Issue