1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-08-02 20:15:26 +02:00

Overhaul the space stats module

Closes #274

All space counters are reset after document and catergory operations.
This commit is contained in:
HarveyKandola 2019-09-24 13:39:57 +01:00
parent 6b723568d3
commit fad1de2e41
7 changed files with 1095 additions and 1142 deletions

View file

@ -105,14 +105,6 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
return
}
err = h.Store.Space.IncrementCategoryCount(ctx, cat.SpaceID)
if err != nil {
ctx.Transaction.Rollback()
response.WriteServerError(w, method, err)
h.Runtime.Log.Error(method, err)
return
}
ctx.Transaction.Commit()
cat, err = h.Store.Category.Get(ctx, cat.RefID)
@ -122,6 +114,7 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
return
}
h.Store.Space.SetStats(ctx, cat.SpaceID)
h.Store.Audit.Record(ctx, audit.EventTypeCategoryAdd)
response.WriteJSON(w, cat)
@ -303,16 +296,9 @@ func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) {
return
}
err = h.Store.Space.DecrementCategoryCount(ctx, cat.SpaceID)
if err != nil {
ctx.Transaction.Rollback()
response.WriteServerError(w, method, err)
h.Runtime.Log.Error(method, err)
return
}
ctx.Transaction.Commit()
h.Store.Space.SetStats(ctx, cat.SpaceID)
h.Store.Audit.Record(ctx, audit.EventTypeCategoryDelete)
response.WriteEmpty(w)