aboutsummaryrefslogtreecommitdiff
path: root/storage/entry.go
diff options
context:
space:
mode:
authorGravatar Shizun Ge <shizunge@gmail.com> 2020-07-01 22:11:36 -0500
committerGravatar GitHub <noreply@github.com> 2020-07-01 20:11:36 -0700
commite32fa059e5929151887e5c926d10f003e34039fb (patch)
treeb761f8eb34458fc877b9b17c12e7ba06d496435e /storage/entry.go
parent3371b1563158ab21e21bfda35bad074a5bc508c3 (diff)
downloadv2-e32fa059e5929151887e5c926d10f003e34039fb.tar.gz
v2-e32fa059e5929151887e5c926d10f003e34039fb.tar.zst
v2-e32fa059e5929151887e5c926d10f003e34039fb.zip
Do not archive shared items
Diffstat (limited to '')
-rw-r--r--storage/entry.go9
1 files changed, 5 insertions, 4 deletions
diff --git a/storage/entry.go b/storage/entry.go
index bf9ed357..a30f4ee9 100644
--- a/storage/entry.go
+++ b/storage/entry.go
@@ -215,15 +215,16 @@ func (s *Storage) ArchiveEntries(days int) error {
return nil
}
+ before := time.Now().AddDate(0, 0, -days)
query := `
UPDATE
entries
SET
- status='removed'
+ status=$1
WHERE
- id=ANY(SELECT id FROM entries WHERE status='read' AND starred is false AND published_at < now () - '%d days'::interval LIMIT 5000)
+ id=ANY(SELECT id FROM entries WHERE status=$2 AND starred is false AND share_code='' AND published_at < $3 LIMIT 5000)
`
- if _, err := s.db.Exec(fmt.Sprintf(query, days)); err != nil {
+ if _, err := s.db.Exec(query, model.EntryStatusRemoved, model.EntryStatusRead, before); err != nil {
return fmt.Errorf(`store: unable to archive read entries: %v`, err)
}
@@ -279,7 +280,7 @@ func (s *Storage) FlushHistory(userID int64) error {
status=$1,
changed_at=now()
WHERE
- user_id=$2 AND status=$3 AND starred='f' AND share_code=''
+ user_id=$2 AND status=$3 AND starred is false AND share_code=''
`
_, err := s.db.Exec(query, model.EntryStatusRemoved, userID, model.EntryStatusRead)
if err != nil {