fix(actions): missing data on retry (#1051)

* fix(actions): missing data on retry

* fix(releases): add missing field in get

* fix(actions): wrong field in scan
This commit is contained in:
ze0s 2023-08-18 00:20:15 +02:00 committed by GitHub
parent 3e244fac10
commit 668e1dbc35
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 98 additions and 177 deletions

View file

@ -115,7 +115,6 @@ func (r *ActionRepo) findByFilterID(ctx context.Context, tx *Tx, filterID int) (
var limitRatio sql.NullFloat64 var limitRatio sql.NullFloat64
var clientID sql.NullInt32 var clientID sql.NullInt32
// filterID
var paused, ignoreRules sql.NullBool var paused, ignoreRules sql.NullBool
if err := rows.Scan(&a.ID, &a.Name, &a.Type, &a.Enabled, &execCmd, &execArgs, &watchFolder, &category, &tags, &label, &savePath, &paused, &ignoreRules, &a.SkipHashCheck, &contentLayout, &limitDl, &limitUl, &limitRatio, &limitSeedTime, &a.ReAnnounceSkip, &a.ReAnnounceDelete, &a.ReAnnounceInterval, &a.ReAnnounceMaxAttempts, &webhookHost, &webhookType, &webhookMethod, &webhookData, &clientID); err != nil { if err := rows.Scan(&a.ID, &a.Name, &a.Type, &a.Enabled, &execCmd, &execArgs, &watchFolder, &category, &tags, &label, &savePath, &paused, &ignoreRules, &a.SkipHashCheck, &contentLayout, &limitDl, &limitUl, &limitRatio, &limitSeedTime, &a.ReAnnounceSkip, &a.ReAnnounceDelete, &a.ReAnnounceInterval, &a.ReAnnounceMaxAttempts, &webhookHost, &webhookType, &webhookMethod, &webhookData, &clientID); err != nil {
@ -147,14 +146,15 @@ func (r *ActionRepo) findByFilterID(ctx context.Context, tx *Tx, filterID int) (
actions = append(actions, &a) actions = append(actions, &a)
} }
if err := rows.Err(); err != nil { if err := rows.Err(); err != nil {
return nil, errors.Wrap(err, "row error") return nil, errors.Wrap(err, "row error")
} }
return actions, nil return actions, nil
} }
func (r *ActionRepo) attachDownloadClient(ctx context.Context, tx *Tx, clientID int32) (*domain.DownloadClient, error) {
func (r *ActionRepo) attachDownloadClient(ctx context.Context, tx *Tx, clientID int32) (*domain.DownloadClient, error) {
queryBuilder := r.db.squirrel. queryBuilder := r.db.squirrel.
Select( Select(
"id", "id",
@ -219,6 +219,8 @@ func (r *ActionRepo) List(ctx context.Context) ([]domain.Action, error) {
"save_path", "save_path",
"paused", "paused",
"ignore_rules", "ignore_rules",
"skip_hash_check",
"content_layout",
"limit_download_speed", "limit_download_speed",
"limit_upload_speed", "limit_upload_speed",
"limit_ratio", "limit_ratio",
@ -251,13 +253,13 @@ func (r *ActionRepo) List(ctx context.Context) ([]domain.Action, error) {
for rows.Next() { for rows.Next() {
var a domain.Action var a domain.Action
var execCmd, execArgs, watchFolder, category, tags, label, savePath, webhookHost, webhookType, webhookMethod, webhookData sql.NullString var execCmd, execArgs, watchFolder, category, tags, label, savePath, contentLayout, webhookHost, webhookType, webhookMethod, webhookData sql.NullString
var limitUl, limitDl, limitSeedTime sql.NullInt64 var limitUl, limitDl, limitSeedTime sql.NullInt64
var limitRatio sql.NullFloat64 var limitRatio sql.NullFloat64
var clientID sql.NullInt32 var clientID sql.NullInt32
var paused, ignoreRules sql.NullBool var paused, ignoreRules sql.NullBool
if err := rows.Scan(&a.ID, &a.Name, &a.Type, &a.Enabled, &execCmd, &execArgs, &watchFolder, &category, &tags, &label, &savePath, &paused, &ignoreRules, &limitDl, &limitUl, &limitRatio, &limitSeedTime, &a.ReAnnounceSkip, &a.ReAnnounceDelete, &a.ReAnnounceInterval, &a.ReAnnounceMaxAttempts, &webhookHost, &webhookType, &webhookMethod, &webhookData, &clientID); err != nil { if err := rows.Scan(&a.ID, &a.Name, &a.Type, &a.Enabled, &execCmd, &execArgs, &watchFolder, &category, &tags, &label, &savePath, &paused, &ignoreRules, &a.SkipHashCheck, &contentLayout, &limitDl, &limitUl, &limitRatio, &limitSeedTime, &a.ReAnnounceSkip, &a.ReAnnounceDelete, &a.ReAnnounceInterval, &a.ReAnnounceMaxAttempts, &webhookHost, &webhookType, &webhookMethod, &webhookData, &clientID); err != nil {
return nil, errors.Wrap(err, "error scanning row") return nil, errors.Wrap(err, "error scanning row")
} }
@ -267,6 +269,7 @@ func (r *ActionRepo) List(ctx context.Context) ([]domain.Action, error) {
a.SavePath = savePath.String a.SavePath = savePath.String
a.Paused = paused.Bool a.Paused = paused.Bool
a.IgnoreRules = ignoreRules.Bool a.IgnoreRules = ignoreRules.Bool
a.ContentLayout = domain.ActionContentLayout(contentLayout.String)
a.LimitDownloadSpeed = limitDl.Int64 a.LimitDownloadSpeed = limitDl.Int64
a.LimitUploadSpeed = limitUl.Int64 a.LimitUploadSpeed = limitUl.Int64
@ -306,6 +309,8 @@ func (r *ActionRepo) Get(ctx context.Context, req *domain.GetActionRequest) (*do
"save_path", "save_path",
"paused", "paused",
"ignore_rules", "ignore_rules",
"skip_hash_check",
"content_layout",
"limit_download_speed", "limit_download_speed",
"limit_upload_speed", "limit_upload_speed",
"limit_ratio", "limit_ratio",
@ -340,13 +345,13 @@ func (r *ActionRepo) Get(ctx context.Context, req *domain.GetActionRequest) (*do
var a domain.Action var a domain.Action
var execCmd, execArgs, watchFolder, category, tags, label, savePath, webhookHost, webhookType, webhookMethod, webhookData sql.NullString var execCmd, execArgs, watchFolder, category, tags, label, savePath, contentLayout, webhookHost, webhookType, webhookMethod, webhookData sql.NullString
var limitUl, limitDl, limitSeedTime sql.NullInt64 var limitUl, limitDl, limitSeedTime sql.NullInt64
var limitRatio sql.NullFloat64 var limitRatio sql.NullFloat64
var clientID, filterID sql.NullInt32 var clientID, filterID sql.NullInt32
var paused, ignoreRules sql.NullBool var paused, ignoreRules sql.NullBool
if err := row.Scan(&a.ID, &a.Name, &a.Type, &a.Enabled, &execCmd, &execArgs, &watchFolder, &category, &tags, &label, &savePath, &paused, &ignoreRules, &limitDl, &limitUl, &limitRatio, &limitSeedTime, &a.ReAnnounceSkip, &a.ReAnnounceDelete, &a.ReAnnounceInterval, &a.ReAnnounceMaxAttempts, &webhookHost, &webhookType, &webhookMethod, &webhookData, &clientID, &filterID); err != nil { if err := row.Scan(&a.ID, &a.Name, &a.Type, &a.Enabled, &execCmd, &execArgs, &watchFolder, &category, &tags, &label, &savePath, &paused, &ignoreRules, &a.SkipHashCheck, &contentLayout, &limitDl, &limitUl, &limitRatio, &limitSeedTime, &a.ReAnnounceSkip, &a.ReAnnounceDelete, &a.ReAnnounceInterval, &a.ReAnnounceMaxAttempts, &webhookHost, &webhookType, &webhookMethod, &webhookData, &clientID, &filterID); err != nil {
if errors.Is(err, sql.ErrNoRows) { if errors.Is(err, sql.ErrNoRows) {
return nil, domain.ErrRecordNotFound return nil, domain.ErrRecordNotFound
} }
@ -363,6 +368,7 @@ func (r *ActionRepo) Get(ctx context.Context, req *domain.GetActionRequest) (*do
a.SavePath = savePath.String a.SavePath = savePath.String
a.Paused = paused.Bool a.Paused = paused.Bool
a.IgnoreRules = ignoreRules.Bool a.IgnoreRules = ignoreRules.Bool
a.ContentLayout = domain.ActionContentLayout(contentLayout.String)
a.LimitDownloadSpeed = limitDl.Int64 a.LimitDownloadSpeed = limitDl.Int64
a.LimitUploadSpeed = limitUl.Int64 a.LimitUploadSpeed = limitUl.Int64
@ -409,8 +415,7 @@ func (r *ActionRepo) DeleteByFilterID(ctx context.Context, filterID int) error {
return errors.Wrap(err, "error building query") return errors.Wrap(err, "error building query")
} }
_, err = r.db.handler.ExecContext(ctx, query, args...) if _, err := r.db.handler.ExecContext(ctx, query, args...); err != nil {
if err != nil {
return errors.Wrap(err, "error executing query") return errors.Wrap(err, "error executing query")
} }
@ -420,26 +425,6 @@ func (r *ActionRepo) DeleteByFilterID(ctx context.Context, filterID int) error {
} }
func (r *ActionRepo) Store(ctx context.Context, action domain.Action) (*domain.Action, error) { func (r *ActionRepo) Store(ctx context.Context, action domain.Action) (*domain.Action, error) {
execCmd := toNullString(action.ExecCmd)
execArgs := toNullString(action.ExecArgs)
watchFolder := toNullString(action.WatchFolder)
category := toNullString(action.Category)
tags := toNullString(action.Tags)
label := toNullString(action.Label)
savePath := toNullString(action.SavePath)
contentLayout := toNullString(string(action.ContentLayout))
webhookHost := toNullString(action.WebhookHost)
webhookData := toNullString(action.WebhookData)
webhookType := toNullString(action.WebhookType)
webhookMethod := toNullString(action.WebhookMethod)
limitDL := toNullInt64(action.LimitDownloadSpeed)
limitUL := toNullInt64(action.LimitUploadSpeed)
limitRatio := toNullFloat64(action.LimitRatio)
limitSeedTime := toNullInt64(action.LimitSeedTime)
clientID := toNullInt32(action.ClientID)
filterID := toNullInt32(int32(action.FilterID))
queryBuilder := r.db.squirrel. queryBuilder := r.db.squirrel.
Insert("action"). Insert("action").
Columns( Columns(
@ -476,31 +461,31 @@ func (r *ActionRepo) Store(ctx context.Context, action domain.Action) (*domain.A
action.Name, action.Name,
action.Type, action.Type,
action.Enabled, action.Enabled,
execCmd, toNullString(action.ExecCmd),
execArgs, toNullString(action.ExecArgs),
watchFolder, toNullString(action.WatchFolder),
category, toNullString(action.Category),
tags, toNullString(action.Tags),
label, toNullString(action.Label),
savePath, toNullString(action.SavePath),
action.Paused, action.Paused,
action.IgnoreRules, action.IgnoreRules,
action.SkipHashCheck, action.SkipHashCheck,
contentLayout, toNullString(string(action.ContentLayout)),
limitUL, toNullInt64(action.LimitUploadSpeed),
limitDL, toNullInt64(action.LimitDownloadSpeed),
limitRatio, toNullFloat64(action.LimitRatio),
limitSeedTime, toNullInt64(action.LimitSeedTime),
action.ReAnnounceSkip, action.ReAnnounceSkip,
action.ReAnnounceDelete, action.ReAnnounceDelete,
action.ReAnnounceInterval, action.ReAnnounceInterval,
action.ReAnnounceMaxAttempts, action.ReAnnounceMaxAttempts,
webhookHost, toNullString(action.WebhookHost),
webhookType, toNullString(action.WebhookType),
webhookMethod, toNullString(action.WebhookMethod),
webhookData, toNullString(action.WebhookData),
clientID, toNullInt32(action.ClientID),
filterID, toNullInt32(int32(action.FilterID)),
). ).
Suffix("RETURNING id").RunWith(r.db.handler) Suffix("RETURNING id").RunWith(r.db.handler)
@ -519,59 +504,36 @@ func (r *ActionRepo) Store(ctx context.Context, action domain.Action) (*domain.A
} }
func (r *ActionRepo) Update(ctx context.Context, action domain.Action) (*domain.Action, error) { func (r *ActionRepo) Update(ctx context.Context, action domain.Action) (*domain.Action, error) {
execCmd := toNullString(action.ExecCmd)
execArgs := toNullString(action.ExecArgs)
watchFolder := toNullString(action.WatchFolder)
category := toNullString(action.Category)
tags := toNullString(action.Tags)
label := toNullString(action.Label)
savePath := toNullString(action.SavePath)
contentLayout := toNullString(string(action.ContentLayout))
webhookHost := toNullString(action.WebhookHost)
webhookType := toNullString(action.WebhookType)
webhookMethod := toNullString(action.WebhookMethod)
webhookData := toNullString(action.WebhookData)
limitDL := toNullInt64(action.LimitDownloadSpeed)
limitUL := toNullInt64(action.LimitUploadSpeed)
limitRatio := toNullFloat64(action.LimitRatio)
limitSeedTime := toNullInt64(action.LimitSeedTime)
clientID := toNullInt32(action.ClientID)
filterID := toNullInt32(int32(action.FilterID))
var err error
queryBuilder := r.db.squirrel. queryBuilder := r.db.squirrel.
Update("action"). Update("action").
Set("name", action.Name). Set("name", action.Name).
Set("type", action.Type). Set("type", action.Type).
Set("enabled", action.Enabled). Set("enabled", action.Enabled).
Set("exec_cmd", execCmd). Set("exec_cmd", toNullString(action.ExecCmd)).
Set("exec_args", execArgs). Set("exec_args", toNullString(action.ExecArgs)).
Set("watch_folder", watchFolder). Set("watch_folder", toNullString(action.WatchFolder)).
Set("category", category). Set("category", toNullString(action.Category)).
Set("tags", tags). Set("tags", toNullString(action.Tags)).
Set("label", label). Set("label", toNullString(action.Label)).
Set("save_path", savePath). Set("save_path", toNullString(action.SavePath)).
Set("paused", action.Paused). Set("paused", action.Paused).
Set("ignore_rules", action.IgnoreRules). Set("ignore_rules", action.IgnoreRules).
Set("skip_hash_check", action.SkipHashCheck). Set("skip_hash_check", action.SkipHashCheck).
Set("content_layout", contentLayout). Set("content_layout", toNullString(string(action.ContentLayout))).
Set("limit_upload_speed", limitUL). Set("limit_upload_speed", toNullInt64(action.LimitUploadSpeed)).
Set("limit_download_speed", limitDL). Set("limit_download_speed", toNullInt64(action.LimitDownloadSpeed)).
Set("limit_ratio", limitRatio). Set("limit_ratio", toNullFloat64(action.LimitRatio)).
Set("limit_seed_time", limitSeedTime). Set("limit_seed_time", toNullInt64(action.LimitSeedTime)).
Set("reannounce_skip", action.ReAnnounceSkip). Set("reannounce_skip", action.ReAnnounceSkip).
Set("reannounce_delete", action.ReAnnounceDelete). Set("reannounce_delete", action.ReAnnounceDelete).
Set("reannounce_interval", action.ReAnnounceInterval). Set("reannounce_interval", action.ReAnnounceInterval).
Set("reannounce_max_attempts", action.ReAnnounceMaxAttempts). Set("reannounce_max_attempts", action.ReAnnounceMaxAttempts).
Set("webhook_host", webhookHost). Set("webhook_host", toNullString(action.WebhookHost)).
Set("webhook_type", webhookType). Set("webhook_type", toNullString(action.WebhookType)).
Set("webhook_method", webhookMethod). Set("webhook_method", toNullString(action.WebhookMethod)).
Set("webhook_data", webhookData). Set("webhook_data", toNullString(action.WebhookData)).
Set("client_id", clientID). Set("client_id", toNullInt32(action.ClientID)).
Set("filter_id", filterID). Set("filter_id", toNullInt32(int32(action.FilterID))).
Where(sq.Eq{"id": action.ID}) Where(sq.Eq{"id": action.ID})
query, args, err := queryBuilder.ToSql() query, args, err := queryBuilder.ToSql()
@ -579,8 +541,7 @@ func (r *ActionRepo) Update(ctx context.Context, action domain.Action) (*domain.
return nil, errors.Wrap(err, "error building query") return nil, errors.Wrap(err, "error building query")
} }
_, err = r.db.handler.ExecContext(ctx, query, args...) if _, err := r.db.handler.ExecContext(ctx, query, args...); err != nil {
if err != nil {
return nil, errors.Wrap(err, "error executing query") return nil, errors.Wrap(err, "error executing query")
} }
@ -601,58 +562,36 @@ func (r *ActionRepo) StoreFilterActions(ctx context.Context, filterID int64, act
action := action action := action
if action.ID > 0 { if action.ID > 0 {
execCmd := toNullString(action.ExecCmd)
execArgs := toNullString(action.ExecArgs)
watchFolder := toNullString(action.WatchFolder)
category := toNullString(action.Category)
tags := toNullString(action.Tags)
label := toNullString(action.Label)
savePath := toNullString(action.SavePath)
contentLayout := toNullString(string(action.ContentLayout))
webhookHost := toNullString(action.WebhookHost)
webhookType := toNullString(action.WebhookType)
webhookMethod := toNullString(action.WebhookMethod)
webhookData := toNullString(action.WebhookData)
limitDL := toNullInt64(action.LimitDownloadSpeed)
limitUL := toNullInt64(action.LimitUploadSpeed)
limitRatio := toNullFloat64(action.LimitRatio)
limitSeedTime := toNullInt64(action.LimitSeedTime)
clientID := toNullInt32(action.ClientID)
var err error
queryBuilder := r.db.squirrel. queryBuilder := r.db.squirrel.
Update("action"). Update("action").
Set("name", action.Name). Set("name", action.Name).
Set("type", action.Type). Set("type", action.Type).
Set("enabled", action.Enabled). Set("enabled", action.Enabled).
Set("exec_cmd", execCmd). Set("exec_cmd", toNullString(action.ExecCmd)).
Set("exec_args", execArgs). Set("exec_args", toNullString(action.ExecArgs)).
Set("watch_folder", watchFolder). Set("watch_folder", toNullString(action.WatchFolder)).
Set("category", category). Set("category", toNullString(action.Category)).
Set("tags", tags). Set("tags", toNullString(action.Tags)).
Set("label", label). Set("label", toNullString(action.Label)).
Set("save_path", savePath). Set("save_path", toNullString(action.SavePath)).
Set("paused", action.Paused). Set("paused", action.Paused).
Set("ignore_rules", action.IgnoreRules). Set("ignore_rules", action.IgnoreRules).
Set("skip_hash_check", action.SkipHashCheck). Set("skip_hash_check", action.SkipHashCheck).
Set("content_layout", contentLayout). Set("content_layout", toNullString(string(action.ContentLayout))).
Set("limit_upload_speed", limitUL). Set("limit_upload_speed", toNullInt64(action.LimitUploadSpeed)).
Set("limit_download_speed", limitDL). Set("limit_download_speed", toNullInt64(action.LimitDownloadSpeed)).
Set("limit_ratio", limitRatio). Set("limit_ratio", toNullFloat64(action.LimitRatio)).
Set("limit_seed_time", limitSeedTime). Set("limit_seed_time", toNullInt64(action.LimitSeedTime)).
Set("reannounce_skip", action.ReAnnounceSkip). Set("reannounce_skip", action.ReAnnounceSkip).
Set("reannounce_delete", action.ReAnnounceDelete). Set("reannounce_delete", action.ReAnnounceDelete).
Set("reannounce_interval", action.ReAnnounceInterval). Set("reannounce_interval", action.ReAnnounceInterval).
Set("reannounce_max_attempts", action.ReAnnounceMaxAttempts). Set("reannounce_max_attempts", action.ReAnnounceMaxAttempts).
Set("webhook_host", webhookHost). Set("webhook_host", toNullString(action.WebhookHost)).
Set("webhook_type", webhookType). Set("webhook_type", toNullString(action.WebhookType)).
Set("webhook_method", webhookMethod). Set("webhook_method", toNullString(action.WebhookMethod)).
Set("webhook_data", webhookData). Set("webhook_data", toNullString(action.WebhookData)).
Set("client_id", clientID). Set("client_id", toNullInt32(action.ClientID)).
Set("filter_id", filterID). Set("filter_id", toNullInt64(filterID)).
Where(sq.Eq{"id": action.ID}) Where(sq.Eq{"id": action.ID})
query, args, err := queryBuilder.ToSql() query, args, err := queryBuilder.ToSql()
@ -660,32 +599,13 @@ func (r *ActionRepo) StoreFilterActions(ctx context.Context, filterID int64, act
return nil, errors.Wrap(err, "error building query") return nil, errors.Wrap(err, "error building query")
} }
if _, err = tx.ExecContext(ctx, query, args...); err != nil { if _, err := tx.ExecContext(ctx, query, args...); err != nil {
return nil, errors.Wrap(err, "error executing query") return nil, errors.Wrap(err, "error executing query")
} }
r.log.Trace().Msgf("action.StoreFilterActions: update %d", action.ID) r.log.Trace().Msgf("action.StoreFilterActions: update %d", action.ID)
} else { } else {
execCmd := toNullString(action.ExecCmd)
execArgs := toNullString(action.ExecArgs)
watchFolder := toNullString(action.WatchFolder)
category := toNullString(action.Category)
tags := toNullString(action.Tags)
label := toNullString(action.Label)
savePath := toNullString(action.SavePath)
contentLayout := toNullString(string(action.ContentLayout))
webhookHost := toNullString(action.WebhookHost)
webhookType := toNullString(action.WebhookType)
webhookMethod := toNullString(action.WebhookMethod)
webhookData := toNullString(action.WebhookData)
limitDL := toNullInt64(action.LimitDownloadSpeed)
limitUL := toNullInt64(action.LimitUploadSpeed)
limitRatio := toNullFloat64(action.LimitRatio)
limitSeedTime := toNullInt64(action.LimitSeedTime)
clientID := toNullInt32(action.ClientID)
queryBuilder := r.db.squirrel. queryBuilder := r.db.squirrel.
Insert("action"). Insert("action").
Columns( Columns(
@ -722,38 +642,38 @@ func (r *ActionRepo) StoreFilterActions(ctx context.Context, filterID int64, act
action.Name, action.Name,
action.Type, action.Type,
action.Enabled, action.Enabled,
execCmd, toNullString(action.ExecCmd),
execArgs, toNullString(action.ExecArgs),
watchFolder, toNullString(action.WatchFolder),
category, toNullString(action.Category),
tags, toNullString(action.Tags),
label, toNullString(action.Label),
savePath, toNullString(action.SavePath),
action.Paused, action.Paused,
action.IgnoreRules, action.IgnoreRules,
action.SkipHashCheck, action.SkipHashCheck,
contentLayout, toNullString(string(action.ContentLayout)),
limitUL, toNullInt64(action.LimitUploadSpeed),
limitDL, toNullInt64(action.LimitDownloadSpeed),
limitRatio, toNullFloat64(action.LimitRatio),
limitSeedTime, toNullInt64(action.LimitSeedTime),
action.ReAnnounceSkip, action.ReAnnounceSkip,
action.ReAnnounceDelete, action.ReAnnounceDelete,
action.ReAnnounceInterval, action.ReAnnounceInterval,
action.ReAnnounceMaxAttempts, action.ReAnnounceMaxAttempts,
webhookHost, toNullString(action.WebhookHost),
webhookType, toNullString(action.WebhookType),
webhookMethod, toNullString(action.WebhookMethod),
webhookData, toNullString(action.WebhookData),
clientID, toNullInt32(action.ClientID),
filterID, toNullInt64(filterID),
). ).
Suffix("RETURNING id").RunWith(tx) Suffix("RETURNING id").RunWith(tx)
// return values // return values
var retID int var retID int
if err = queryBuilder.QueryRowContext(ctx).Scan(&retID); err != nil { if err := queryBuilder.QueryRowContext(ctx).Scan(&retID); err != nil {
return nil, errors.Wrap(err, "error executing query") return nil, errors.Wrap(err, "error executing query")
} }
@ -762,7 +682,7 @@ func (r *ActionRepo) StoreFilterActions(ctx context.Context, filterID int64, act
r.log.Trace().Msgf("action.StoreFilterActions: store %d", action.ID) r.log.Trace().Msgf("action.StoreFilterActions: store %d", action.ID)
} }
r.log.Debug().Msgf("action.StoreFilterActions: store '%v' type: '%v' on filter: %v", action.Name, action.Type, filterID) r.log.Debug().Msgf("action.StoreFilterActions: store '%s' type: '%v' on filter: %d", action.Name, action.Type, filterID)
} }
if err := tx.Commit(); err != nil { if err := tx.Commit(); err != nil {
@ -773,8 +693,6 @@ func (r *ActionRepo) StoreFilterActions(ctx context.Context, filterID int64, act
} }
func (r *ActionRepo) ToggleEnabled(actionID int) error { func (r *ActionRepo) ToggleEnabled(actionID int) error {
var err error
queryBuilder := r.db.squirrel. queryBuilder := r.db.squirrel.
Update("action"). Update("action").
Set("enabled", sq.Expr("NOT enabled")). Set("enabled", sq.Expr("NOT enabled")).
@ -785,8 +703,7 @@ func (r *ActionRepo) ToggleEnabled(actionID int) error {
return errors.Wrap(err, "error building query") return errors.Wrap(err, "error building query")
} }
_, err = r.db.handler.Exec(query, args...) if _, err := r.db.handler.Exec(query, args...); err != nil {
if err != nil {
return errors.Wrap(err, "error executing query") return errors.Wrap(err, "error executing query")
} }

View file

@ -398,7 +398,7 @@ func (repo *ReleaseRepo) GetActionStatusByReleaseID(ctx context.Context, release
func (repo *ReleaseRepo) Get(ctx context.Context, req *domain.GetReleaseRequest) (*domain.Release, error) { func (repo *ReleaseRepo) Get(ctx context.Context, req *domain.GetReleaseRequest) (*domain.Release, error) {
queryBuilder := repo.db.squirrel. queryBuilder := repo.db.squirrel.
Select("r.id", "r.filter_status", "r.rejections", "r.indexer", "r.filter", "r.filter_id", "r.protocol", "r.info_url", "r.download_url", "r.title", "r.torrent_name", "r.size", "r.timestamp"). Select("r.id", "r.filter_status", "r.rejections", "r.indexer", "r.filter", "r.filter_id", "r.protocol", "r.implementation", "r.info_url", "r.download_url", "r.title", "r.torrent_name", "r.category", "r.size", "r.group_id", "r.torrent_id", "r.uploader", "r.timestamp").
From("release r"). From("release r").
OrderBy("r.id DESC"). OrderBy("r.id DESC").
Where(sq.Eq{"r.id": req.Id}) Where(sq.Eq{"r.id": req.Id})
@ -408,7 +408,7 @@ func (repo *ReleaseRepo) Get(ctx context.Context, req *domain.GetReleaseRequest)
return nil, errors.Wrap(err, "error building query") return nil, errors.Wrap(err, "error building query")
} }
repo.log.Trace().Str("database", "release.find").Msgf("query: '%v', args: '%v'", query, args) repo.log.Trace().Str("database", "release.find").Msgf("query: '%s', args: '%v'", query, args)
row := repo.db.handler.QueryRowContext(ctx, query, args...) row := repo.db.handler.QueryRowContext(ctx, query, args...)
if err != nil { if err != nil {
@ -421,10 +421,10 @@ func (repo *ReleaseRepo) Get(ctx context.Context, req *domain.GetReleaseRequest)
var rls domain.Release var rls domain.Release
var indexerName, filterName, infoUrl, downloadUrl sql.NullString var indexerName, filterName, infoUrl, downloadUrl, groupId, torrentId, category, uploader sql.NullString
var filterId sql.NullInt64 var filterId sql.NullInt64
if err := row.Scan(&rls.ID, &rls.FilterStatus, pq.Array(&rls.Rejections), &indexerName, &filterName, &filterId, &rls.Protocol, &infoUrl, &downloadUrl, &rls.Title, &rls.TorrentName, &rls.Size, &rls.Timestamp); err != nil { if err := row.Scan(&rls.ID, &rls.FilterStatus, pq.Array(&rls.Rejections), &indexerName, &filterName, &filterId, &rls.Protocol, &rls.Implementation, &infoUrl, &downloadUrl, &rls.Title, &rls.TorrentName, &category, &rls.Size, &groupId, &torrentId, &uploader, &rls.Timestamp); err != nil {
if errors.Is(err, sql.ErrNoRows) { if errors.Is(err, sql.ErrNoRows) {
return nil, nil return nil, nil
} }
@ -437,6 +437,10 @@ func (repo *ReleaseRepo) Get(ctx context.Context, req *domain.GetReleaseRequest)
rls.ActionStatus = make([]domain.ReleaseActionStatus, 0) rls.ActionStatus = make([]domain.ReleaseActionStatus, 0)
rls.InfoURL = infoUrl.String rls.InfoURL = infoUrl.String
rls.TorrentURL = downloadUrl.String rls.TorrentURL = downloadUrl.String
rls.Category = category.String
rls.GroupID = groupId.String
rls.TorrentID = torrentId.String
rls.Uploader = uploader.String
return &rls, nil return &rls, nil
} }