mirror of
https://github.com/documize/community.git
synced 2025-07-19 05:09:42 +02:00
Better handling for document.update TX
This commit is contained in:
parent
811e239baf
commit
2d105f2154
1 changed files with 10 additions and 8 deletions
|
@ -231,17 +231,18 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
d.RefID = documentID
|
d.RefID = documentID
|
||||||
|
|
||||||
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
var ok bool
|
||||||
if err != nil {
|
ctx.Transaction, ok = h.Runtime.StartTx(sql.LevelReadUncommitted)
|
||||||
|
if !ok {
|
||||||
|
h.Runtime.Log.Info("unable to start transaction " + method)
|
||||||
response.WriteServerError(w, method, err)
|
response.WriteServerError(w, method, err)
|
||||||
h.Runtime.Log.Error(method, err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// If space changed for document, remove document categories.
|
// If space changed for document, remove document categories.
|
||||||
oldDoc, err := h.Store.Document.Get(ctx, documentID)
|
oldDoc, err := h.Store.Document.Get(ctx, documentID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Transaction.Rollback()
|
h.Runtime.Rollback(ctx.Transaction)
|
||||||
response.WriteServerError(w, method, err)
|
response.WriteServerError(w, method, err)
|
||||||
h.Runtime.Log.Error(method, err)
|
h.Runtime.Log.Error(method, err)
|
||||||
return
|
return
|
||||||
|
@ -251,7 +252,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
||||||
h.Store.Category.RemoveDocumentCategories(ctx, d.RefID)
|
h.Store.Category.RemoveDocumentCategories(ctx, d.RefID)
|
||||||
err = h.Store.Document.MoveActivity(ctx, documentID, oldDoc.SpaceID, d.SpaceID)
|
err = h.Store.Document.MoveActivity(ctx, documentID, oldDoc.SpaceID, d.SpaceID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Transaction.Rollback()
|
h.Runtime.Rollback(ctx.Transaction)
|
||||||
response.WriteServerError(w, method, err)
|
response.WriteServerError(w, method, err)
|
||||||
h.Runtime.Log.Error(method, err)
|
h.Runtime.Log.Error(method, err)
|
||||||
return
|
return
|
||||||
|
@ -260,7 +261,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
err = h.Store.Document.Update(ctx, d)
|
err = h.Store.Document.Update(ctx, d)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Transaction.Rollback()
|
h.Runtime.Rollback(ctx.Transaction)
|
||||||
response.WriteServerError(w, method, err)
|
response.WriteServerError(w, method, err)
|
||||||
h.Runtime.Log.Error(method, err)
|
h.Runtime.Log.Error(method, err)
|
||||||
return
|
return
|
||||||
|
@ -272,7 +273,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
||||||
if len(d.GroupID) > 0 {
|
if len(d.GroupID) > 0 {
|
||||||
err = h.Store.Document.UpdateGroup(ctx, d)
|
err = h.Store.Document.UpdateGroup(ctx, d)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Transaction.Rollback()
|
h.Runtime.Rollback(ctx.Transaction)
|
||||||
response.WriteServerError(w, method, err)
|
response.WriteServerError(w, method, err)
|
||||||
h.Runtime.Log.Error(method, err)
|
h.Runtime.Log.Error(method, err)
|
||||||
return
|
return
|
||||||
|
@ -309,12 +310,13 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Transaction.Commit()
|
h.Runtime.Commit(ctx.Transaction)
|
||||||
|
|
||||||
h.Store.Space.SetStats(ctx, d.SpaceID)
|
h.Store.Space.SetStats(ctx, d.SpaceID)
|
||||||
if oldDoc.SpaceID != d.SpaceID {
|
if oldDoc.SpaceID != d.SpaceID {
|
||||||
h.Store.Space.SetStats(ctx, oldDoc.SpaceID)
|
h.Store.Space.SetStats(ctx, oldDoc.SpaceID)
|
||||||
}
|
}
|
||||||
|
|
||||||
h.Store.Audit.Record(ctx, audit.EventTypeDocumentUpdate)
|
h.Store.Audit.Record(ctx, audit.EventTypeDocumentUpdate)
|
||||||
|
|
||||||
// Live document indexed for search.
|
// Live document indexed for search.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue