mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 16:59:12 +00:00
feat(filters): show enabled and disabled actions in list view (#1304)
* feat(filters): reflect enabled actions * dont store release unless enabled action found * store the release after the delay * add new parameter to FindByFilterID method
This commit is contained in:
parent
95cd053db5
commit
6e12654f6a
11 changed files with 59 additions and 45 deletions
|
@ -30,7 +30,7 @@ func NewActionRepo(log logger.Logger, db *DB, clientRepo domain.DownloadClientRe
|
|||
}
|
||||
}
|
||||
|
||||
func (r *ActionRepo) FindByFilterID(ctx context.Context, filterID int) ([]*domain.Action, error) {
|
||||
func (r *ActionRepo) FindByFilterID(ctx context.Context, filterID int, active *bool) ([]*domain.Action, error) {
|
||||
tx, err := r.db.BeginTx(ctx, &sql.TxOptions{Isolation: sql.LevelReadCommitted})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -38,7 +38,7 @@ func (r *ActionRepo) FindByFilterID(ctx context.Context, filterID int) ([]*domai
|
|||
|
||||
defer tx.Rollback()
|
||||
|
||||
actions, err := r.findByFilterID(ctx, tx, filterID)
|
||||
actions, err := r.findByFilterID(ctx, tx, filterID, active)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ func (r *ActionRepo) FindByFilterID(ctx context.Context, filterID int) ([]*domai
|
|||
return actions, nil
|
||||
}
|
||||
|
||||
func (r *ActionRepo) findByFilterID(ctx context.Context, tx *Tx, filterID int) ([]*domain.Action, error) {
|
||||
func (r *ActionRepo) findByFilterID(ctx context.Context, tx *Tx, filterID int, active *bool) ([]*domain.Action, error) {
|
||||
queryBuilder := r.db.squirrel.
|
||||
Select(
|
||||
"id",
|
||||
|
@ -95,6 +95,10 @@ func (r *ActionRepo) findByFilterID(ctx context.Context, tx *Tx, filterID int) (
|
|||
From("action").
|
||||
Where(sq.Eq{"filter_id": filterID})
|
||||
|
||||
if active != nil {
|
||||
queryBuilder = queryBuilder.Where(sq.Eq{"enabled": *active})
|
||||
}
|
||||
|
||||
query, args, err := queryBuilder.ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "error building query")
|
||||
|
|
|
@ -214,7 +214,7 @@ func TestActionRepo_FindByFilterID(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
|
||||
// Actual test for FindByFilterID
|
||||
actions, err := repo.FindByFilterID(context.Background(), createdFilters[0].ID)
|
||||
actions, err := repo.FindByFilterID(context.Background(), createdFilters[0].ID, nil)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, actions)
|
||||
assert.Equal(t, 1, len(actions))
|
||||
|
@ -235,7 +235,7 @@ func TestActionRepo_FindByFilterID(t *testing.T) {
|
|||
assert.NotNil(t, createdFilters)
|
||||
|
||||
// Actual test for FindByFilterID
|
||||
actions, err := repo.FindByFilterID(context.Background(), createdFilters[0].ID)
|
||||
actions, err := repo.FindByFilterID(context.Background(), createdFilters[0].ID, nil)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, 0, len(actions))
|
||||
|
||||
|
@ -244,7 +244,7 @@ func TestActionRepo_FindByFilterID(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run(fmt.Sprintf("FindByFilterID_Succeeds_With_Invalid_FilterID [%s]", dbType), func(t *testing.T) {
|
||||
actions, err := repo.FindByFilterID(context.Background(), 9999) // 9999 is an invalid filter ID
|
||||
actions, err := repo.FindByFilterID(context.Background(), 9999, nil) // 9999 is an invalid filter ID
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, actions)
|
||||
assert.Equal(t, 0, len(actions))
|
||||
|
@ -254,7 +254,7 @@ func TestActionRepo_FindByFilterID(t *testing.T) {
|
|||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Nanosecond)
|
||||
defer cancel()
|
||||
|
||||
actions, err := repo.FindByFilterID(ctx, 1)
|
||||
actions, err := repo.FindByFilterID(ctx, 1, nil)
|
||||
assert.Error(t, err)
|
||||
assert.Nil(t, actions)
|
||||
})
|
||||
|
|
|
@ -57,6 +57,12 @@ func (r *FilterRepo) find(ctx context.Context, tx *Tx, params domain.FilterQuery
|
|||
From("action a").
|
||||
Where("a.filter_id = f.id")
|
||||
|
||||
actionEnabledCountQuery := r.db.squirrel.
|
||||
Select("COUNT(*)").
|
||||
From("action a").
|
||||
Where("a.filter_id = f.id").
|
||||
Where("a.enabled = '1'")
|
||||
|
||||
queryBuilder := r.db.squirrel.
|
||||
Select(
|
||||
"f.id",
|
||||
|
@ -68,6 +74,7 @@ func (r *FilterRepo) find(ctx context.Context, tx *Tx, params domain.FilterQuery
|
|||
).
|
||||
Distinct().
|
||||
Column(sq.Alias(actionCountQuery, "action_count")).
|
||||
Column(sq.Alias(actionEnabledCountQuery, "actions_enabled_count")).
|
||||
LeftJoin("filter_indexer fi ON f.id = fi.filter_id").
|
||||
LeftJoin("indexer i ON i.id = fi.indexer_id").
|
||||
From("filter f")
|
||||
|
@ -89,7 +96,6 @@ func (r *FilterRepo) find(ctx context.Context, tx *Tx, params domain.FilterQuery
|
|||
for _, v := range params.Filters.Indexers {
|
||||
filter = append(filter, sq.Eq{"i.identifier": v})
|
||||
}
|
||||
|
||||
queryBuilder = queryBuilder.Where(filter)
|
||||
}
|
||||
|
||||
|
@ -102,14 +108,13 @@ func (r *FilterRepo) find(ctx context.Context, tx *Tx, params domain.FilterQuery
|
|||
if err != nil {
|
||||
return nil, errors.Wrap(err, "error executing query")
|
||||
}
|
||||
|
||||
defer rows.Close()
|
||||
|
||||
var filters []domain.Filter
|
||||
for rows.Next() {
|
||||
var f domain.Filter
|
||||
|
||||
if err := rows.Scan(&f.ID, &f.Enabled, &f.Name, &f.Priority, &f.CreatedAt, &f.UpdatedAt, &f.ActionsCount); err != nil {
|
||||
if err := rows.Scan(&f.ID, &f.Enabled, &f.Name, &f.Priority, &f.CreatedAt, &f.UpdatedAt, &f.ActionsCount, &f.ActionsEnabledCount); err != nil {
|
||||
return nil, errors.Wrap(err, "error scanning row")
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue