Compare commits

...
6 Commits
Author SHA1 Message Date
gisle b5c77cf8ca try fix again again again again again.
continuous-integration/drone/push Build is passing
2021-07-26 22:18:31 +02:00
gisle 3045931492 try fix again again again again.
continuous-integration/drone/push Build is passing
2021-07-26 21:43:10 +02:00
gisle 928e643ab7 try fix again again again. 2021-07-26 21:26:53 +02:00
gisle 6b1f34db79 try fix again again.
continuous-integration/drone/push Build is passing
2021-07-26 20:56:46 +02:00
gisle bd27b14a88 try fix again.
continuous-integration/drone/push Build is passing
2021-07-26 20:50:03 +02:00
gisle 4bccdc2ded hopefully fix the bug preventing post deletions sometimes.
continuous-integration/drone/push Build is passing
2021-07-26 20:32:55 +02:00
4 changed files with 36 additions and 9 deletions
@@ -0,0 +1,13 @@
-- +goose Up
-- +goose StatementBegin
ALTER TABLE log_post
DROP CONSTRAINT log_post_log_short_id_position_key,
ADD CONSTRAINT log_post_log_short_id_position_key UNIQUE(log_short_id, position) DEFERRABLE;
-- +goose StatementEnd
-- +goose Down
-- +goose StatementBegin
ALTER TABLE log_post
DROP CONSTRAINT log_post_log_short_id_position_key,
ADD CONSTRAINT log_post_log_short_id_position_key UNIQUE(log_short_id, position);
-- +goose StatementEnd
+10 -4
View File
@@ -4,6 +4,7 @@ import (
"context"
"database/sql"
"errors"
"fmt"
"git.aiterp.net/rpdata/api/database/postgres/psqlcore"
"git.aiterp.net/rpdata/api/internal/generate"
"git.aiterp.net/rpdata/api/models"
@@ -253,9 +254,9 @@ func (r *postRepository) Delete(ctx context.Context, post models.Post) error {
return err
}
err = q.DeletePost(ctx, post.ID)
err = q.MovePost(ctx, psqlcore.MovePostParams{ID: post.ID, Position: -1})
if err != nil {
return err
return fmt.Errorf("pre-delete move failed: %s", err)
}
err = q.ShiftPostsAfter(ctx, psqlcore.ShiftPostsAfterParams{
@@ -264,12 +265,17 @@ func (r *postRepository) Delete(ctx context.Context, post models.Post) error {
FromPosition: int32(post.Position + 1),
})
if err != nil {
return err
return fmt.Errorf("shift failed: %s", err)
}
err = q.DeletePost(ctx, post.ID)
if err != nil {
return fmt.Errorf("delete failed: %s", err)
}
err = tx.Commit()
if err != nil {
return err
return fmt.Errorf("tx commit failed: %s", err)
}
_ = psqlcore.New(r.db).GenerateLogTSVector(ctx, post.LogID)
+8 -1
View File
@@ -56,7 +56,7 @@ func (s *AuthService) FindKey(ctx context.Context, id string) (*models.Key, erro
return s.keys.Find(ctx, id)
}
// FindKey finds a key by id.
// FindUser finds a user by id.
func (s *AuthService) FindUser(ctx context.Context, id string) (*models.User, error) {
return s.users.Find(ctx, id)
}
@@ -154,6 +154,13 @@ func (s *AuthService) TokenFromContext(ctx context.Context) *models.Token {
return token
}
// SpinOffContext adds the auth token to a background context.
func (s *AuthService) SpinOffContext(ctx context.Context) context.Context {
token := s.TokenFromContext(ctx)
return context.WithValue(context.Background(), contextKey, token)
}
// RequestWithToken either returns the request, or the request with a new context that
// has the token.
func (s *AuthService) RequestWithToken(r *http.Request) *http.Request {
+5 -4
View File
@@ -484,15 +484,16 @@ func (s *LogService) EditPost(ctx context.Context, id string, update models.Post
return nil, err
}
spinOffCtx := s.authService.SpinOffContext(ctx)
go func() {
l, err := s.logs.Find(context.Background(), post.LogID)
timeout, cancel := context.WithTimeout(spinOffCtx, time.Minute*10)
defer cancel()
l, err := s.logs.Find(timeout, post.LogID)
if err != nil {
return
}
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)