Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b5c77cf8ca | ||
|
|
3045931492 | ||
|
|
928e643ab7 | ||
|
|
6b1f34db79 | ||
|
|
bd27b14a88 | ||
|
|
4bccdc2ded |
@@ -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
|
||||
@@ -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
@@ -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
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user