From 247c142b8d5ea36d3ba131159f8e83874e054db1 Mon Sep 17 00:00:00 2001 From: romanskijdev Date: Thu, 18 Jun 2026 17:47:56 +0300 Subject: [PATCH] fixed executors db freezing --- core/db/methods/approval_topic_executor.go | 56 ++++++++++++++++++- .../handlers/topic_executors/handlers.go | 11 ---- 2 files changed, 55 insertions(+), 12 deletions(-) diff --git a/core/db/methods/approval_topic_executor.go b/core/db/methods/approval_topic_executor.go index 681026e..c2c84ba 100644 --- a/core/db/methods/approval_topic_executor.go +++ b/core/db/methods/approval_topic_executor.go @@ -27,6 +27,60 @@ type ApprovalTopicExecutorDBI interface { UpdateApprovalTopicExecutorDB(ctx context.Context, tx pgx.Tx, paramsUpdate *typescore.ApprovalTopicExecutor, returnObj ...bool) (*typescore.ApprovalTopicExecutor, pgx.Tx, error) DeleteApprovalTopicExecutorDB(ctx context.Context, params *typescore.ApprovalTopicExecutor) error GetExecutorsByTopicIDDB(ctx context.Context, topicID uint64) ([]*typescore.ApprovalTopicExecutor, error) + GetApprovalTopicExecutorListWithParamsDB(ctx context.Context, opts typescore.ListDbOptions) ([]*typescore.ApprovalTopicExecutor, uint64, error) +} + +func (d *ApprovalTopicExecutorDB) GetApprovalTopicExecutorListWithParamsDB(ctx context.Context, opts typescore.ListDbOptions) ([]*typescore.ApprovalTopicExecutor, uint64, error) { + options, filter, err := dbutils.GetOptionsDB[typescore.ApprovalTopicExecutor](opts) + if err != nil { + return nil, 0, err + } + query := squirrel.Select( + "ate.*", + "u.id", "u.full_name", "u.username", + "t.id", "t.name", + "COUNT(*) OVER() AS total_count", + ). + From("approval_topic_executors ate"). + LeftJoin("users u ON ate.user_id = u.id"). + LeftJoin("approval_topics t ON ate.topic_id = t.id") + + query = dbutils.SetterLimitAndOffsetQuery(query, options.Offset, options.Limit) + query = dbutils.ApplyFilters(query, filter, options.LikeFields, dbcoretablenames.TableNameApprovalTopicExecutor.ToString()) + query = query.OrderBy("step_order ASC, id ASC") + + sql, args, err := query.PlaceholderFormat(squirrel.Dollar).ToSql() + if err != nil { + return nil, 0, err + } + + rows, err := d.pool.Query(ctx, sql, args...) + if err != nil { + return nil, 0, err + } + defer rows.Close() + + var results []*typescore.ApprovalTopicExecutor + var totalCount uint64 + + for rows.Next() { + exec := &typescore.ApprovalTopicExecutor{} + exec.User = &typescore.User{} + exec.Topic = &typescore.ApprovalTopic{} + + err := rows.Scan( + &exec.ID, &exec.TopicID, &exec.UserID, &exec.StepOrder, &exec.RequireFile, &exec.IsActive, &exec.CreatedAt, &exec.UpdatedAt, + &exec.User.ID, &exec.User.FullName, &exec.User.Username, + &exec.Topic.ID, &exec.Topic.Name, + &totalCount, + ) + if err != nil { + return nil, 0, err + } + results = append(results, exec) + } + + return results, totalCount, nil } func (d *ApprovalTopicExecutorDB) GetApprovalTopicExecutorListDB(ctx context.Context, opts ...typescore.ListDbOptions) ([]*typescore.ApprovalTopicExecutor, uint64, error) { @@ -161,7 +215,7 @@ func (d *ApprovalTopicExecutorDB) DeleteApprovalTopicExecutorDB(ctx context.Cont return err } - _, err = d.pool.Query(ctx, query, args...) + _, err = d.pool.Exec(ctx, query, args...) return err } return errors.New("ApprovalTopicExecutor obj is nil") diff --git a/service/rest_admin_service/handlers/topic_executors/handlers.go b/service/rest_admin_service/handlers/topic_executors/handlers.go index 5c864a5..cc35b9a 100644 --- a/service/rest_admin_service/handlers/topic_executors/handlers.go +++ b/service/rest_admin_service/handlers/topic_executors/handlers.go @@ -376,17 +376,6 @@ func (s *TopicExecutorsReg) DeleteTopicExecutorHandler(w http.ResponseWriter, r ctx := r.Context() - // Проверяем, что запись существует - existingExecutors, _, err := s.ipc.Database.ApprovalTopicExecutor.GetApprovalTopicExecutorListDB(ctx, typescore.ListDbOptions{ - Filtering: &typescore.ApprovalTopicExecutor{ID: req.ID}, - }) - if err != nil { - return nil, err - } - if len(existingExecutors) == 0 { - return nil, errors.New("topic executor not found") - } - err = s.ipc.Database.ApprovalTopicExecutor.DeleteApprovalTopicExecutorDB(ctx, &req) if err != nil { return nil, err -- 2.43.0