mirror of
https://github.com/christianselig/apollo-backend
synced 2024-12-25 15:55:28 +00:00
delete devices heuristic fix
This commit is contained in:
parent
65202112f9
commit
a26b1f6a32
2 changed files with 3 additions and 10 deletions
|
@ -146,10 +146,10 @@ func pruneAccounts(ctx context.Context, logger *logrus.Logger, pool *pgxpool.Poo
|
|||
}
|
||||
|
||||
func pruneDevices(ctx context.Context, logger *logrus.Logger, pool *pgxpool.Pool) {
|
||||
before := time.Now().Unix() - staleDeviceThreshold
|
||||
threshold := time.Now().Unix()
|
||||
dr := repository.NewPostgresDevice(pool)
|
||||
|
||||
count, err := dr.PruneStale(ctx, before)
|
||||
count, err := dr.PruneStale(ctx, threshold)
|
||||
if err != nil {
|
||||
logger.WithFields(logrus.Fields{
|
||||
"err": err,
|
||||
|
|
|
@ -143,14 +143,7 @@ func (p *postgresDeviceRepository) Delete(ctx context.Context, token string) err
|
|||
}
|
||||
|
||||
func (p *postgresDeviceRepository) PruneStale(ctx context.Context, before int64) (int64, error) {
|
||||
query := `
|
||||
WITH deleted_devices AS (
|
||||
DELETE FROM devices
|
||||
WHERE active_until < $1
|
||||
RETURNING id
|
||||
)
|
||||
DELETE FROM devices_accounts
|
||||
WHERE device_id IN (SELECT id FROM deleted_devices)`
|
||||
query := `DELETE FROM devices WHERE active_until < $1`
|
||||
|
||||
res, err := p.pool.Exec(ctx, query, before)
|
||||
|
||||
|
|
Loading…
Reference in a new issue