|
@@ -3,7 +3,7 @@ package datacleanup
|
|
|
import (
|
|
|
"context"
|
|
|
"database/sql"
|
|
|
-
|
|
|
+ "fmt"
|
|
|
entity "github.com/ente-io/museum/ente/data_cleanup"
|
|
|
"github.com/ente-io/museum/pkg/utils/time"
|
|
|
"github.com/ente-io/stacktrace"
|
|
@@ -19,6 +19,21 @@ func (r *Repository) Insert(ctx context.Context, userID int64) error {
|
|
|
return stacktrace.Propagate(err, "failed to insert")
|
|
|
}
|
|
|
|
|
|
+func (r *Repository) RemoveScheduledDelete(ctx context.Context, userID int64) error {
|
|
|
+ res, execErr := r.DB.ExecContext(ctx, `DELETE from data_cleanup where user_id= $1 and stage = $2`, userID, entity.Scheduled)
|
|
|
+ if execErr != nil {
|
|
|
+ return execErr
|
|
|
+ }
|
|
|
+ affected, affErr := res.RowsAffected()
|
|
|
+ if affErr != nil {
|
|
|
+ return affErr
|
|
|
+ }
|
|
|
+ if affected != 1 {
|
|
|
+ return fmt.Errorf("only one row should have been affected, got %d", affected)
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
func (r *Repository) GetItemsPendingCompletion(ctx context.Context, limit int) ([]*entity.DataCleanup, error) {
|
|
|
rows, err := r.DB.QueryContext(ctx, `SELECT user_id, stage, stage_schedule_time, stage_attempt_count, created_at, updated_at from data_cleanup
|
|
|
where stage != $1 and stage_schedule_time < now_utc_micro_seconds()
|