From 67d6161c3bb0ef7cb04a1298d0e388940ddeb3fc Mon Sep 17 00:00:00 2001 From: Gisle Aune Date: Mon, 26 Jul 2021 20:15:51 +0200 Subject: [PATCH] fix characters not updating on edit post and (hopefully) the bug preventing post deletions sometimes. --- database/postgres/posts.go | 9 +++++++-- services/logs.go | 9 ++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/database/postgres/posts.go b/database/postgres/posts.go index e189f37..a0373e7 100644 --- a/database/postgres/posts.go +++ b/database/postgres/posts.go @@ -267,9 +267,14 @@ func (r *postRepository) Delete(ctx context.Context, post models.Post) error { return err } - _ = q.GenerateLogTSVector(ctx, post.LogID) + err = tx.Commit() + if err != nil { + return err + } + + _ = psqlcore.New(r.db).GenerateLogTSVector(ctx, post.LogID) - return tx.Commit() + return nil } func (r *postRepository) post(post psqlcore.SelectPostRow) *models.Post { diff --git a/services/logs.go b/services/logs.go index 7b0ef29..dd108da 100644 --- a/services/logs.go +++ b/services/logs.go @@ -490,12 +490,15 @@ func (s *LogService) EditPost(ctx context.Context, id string, update models.Post return } - _, err = s.refreshLogCharacters(ctx, *l, nil, false) + timeout, cancel := context.WithTimeout(context.Background(), time.Minute*10) + defer cancel() + + s.changeService.Submit(timeout, models.ChangeModelPost, "edit", true, changekeys.Many(l, post), post) + + _, err = s.refreshLogCharacters(timeout, *l, nil, false) if err != nil { log.Printf("Failed to update characters in log %s: %s", l.ID, err) } - - s.changeService.Submit(ctx, models.ChangeModelPost, "edit", true, changekeys.Many(l, post), post) }() return post, nil