mirror of
https://github.com/miniflux/v2.git
synced 2025-08-26 18:21:01 +00:00
refactor(storage): split DeleteContentRemovedEntries
into 2 functions and fix condition
- Add `content IS NOT NULL` to avoid clearing the same entries over and over - Create `DeleteRemovedEntriesEnclosures` and `ClearRemovedEntriesContent` that report individual counts
This commit is contained in:
parent
5c26e06780
commit
a16ac51326
2 changed files with 34 additions and 18 deletions
|
@ -258,8 +258,8 @@ func (s *Storage) GetReadTime(feedID int64, entryHash string) int {
|
|||
return result
|
||||
}
|
||||
|
||||
// deleteRemovedNonexistentEntries deletes from the database entries marked as "removed" and not visible anymore in the feed.
|
||||
func (s *Storage) deleteRemovedNonexistentEntries(feedID int64, entryHashes []string) error {
|
||||
// cleanupRemovedEntriesNotInFeed deletes from the database entries marked as "removed" and not visible anymore in the feed.
|
||||
func (s *Storage) cleanupRemovedEntriesNotInFeed(feedID int64, entryHashes []string) error {
|
||||
query := `
|
||||
DELETE FROM
|
||||
entries
|
||||
|
@ -275,21 +275,30 @@ func (s *Storage) deleteRemovedNonexistentEntries(feedID int64, entryHashes []st
|
|||
return nil
|
||||
}
|
||||
|
||||
// deleteContentRemovedEntries deletes the content and corresponding enclosures
|
||||
// of entries marked as "removed", and only keeps their metadata.
|
||||
func (s *Storage) DeleteContentRemovedEntries() (int64, error) {
|
||||
// DeleteRemovedEntriesEnclosures deletes enclosures associated with entries marked as "removed".
|
||||
func (s *Storage) DeleteRemovedEntriesEnclosures() (int64, error) {
|
||||
query := `
|
||||
DELETE FROM
|
||||
enclosures
|
||||
WHERE
|
||||
enclosures.entry_id IN
|
||||
(SELECT id FROM entries WHERE status=$1)
|
||||
enclosures.entry_id IN (SELECT id FROM entries WHERE status=$1)
|
||||
`
|
||||
if _, err := s.db.Exec(query, model.EntryStatusRemoved); err != nil {
|
||||
result, err := s.db.Exec(query, model.EntryStatusRemoved)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf(`store: unable to delete enclosures from removed entries: %v`, err)
|
||||
}
|
||||
|
||||
query = `
|
||||
count, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf(`store: unable to get the number of rows affected while deleting enclosures from removed entries: %v`, err)
|
||||
}
|
||||
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// ClearRemovedEntriesContent clears the content fields of entries marked as "removed", keeping only their metadata.
|
||||
func (s *Storage) ClearRemovedEntriesContent() (int64, error) {
|
||||
query := `
|
||||
UPDATE
|
||||
entries
|
||||
SET
|
||||
|
@ -298,17 +307,17 @@ func (s *Storage) DeleteContentRemovedEntries() (int64, error) {
|
|||
url='',
|
||||
author=NULL
|
||||
WHERE
|
||||
status=$1
|
||||
status=$1 AND content IS NOT NULL
|
||||
`
|
||||
|
||||
result, err := s.db.Exec(query, model.EntryStatusRemoved)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf(`store: unable to delete removed entries: %v`, err)
|
||||
return 0, fmt.Errorf(`store: unable to clear content from removed entries: %v`, err)
|
||||
}
|
||||
|
||||
count, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf(`store: unable to get the number of rows affected while deleting content from removed entries: %v`, err)
|
||||
return 0, fmt.Errorf(`store: unable to get the number of rows affected while clearing content from removed entries: %v`, err)
|
||||
}
|
||||
|
||||
return count, nil
|
||||
|
@ -361,8 +370,8 @@ func (s *Storage) RefreshFeedEntries(userID, feedID int64, entries model.Entries
|
|||
}
|
||||
|
||||
go func() {
|
||||
if err := s.deleteRemovedNonexistentEntries(feedID, entryHashes); err != nil {
|
||||
slog.Error("Unable to cleanup entries",
|
||||
if err := s.cleanupRemovedEntriesNotInFeed(feedID, entryHashes); err != nil {
|
||||
slog.Error("Unable to cleanup removed entries",
|
||||
slog.Int64("user_id", userID),
|
||||
slog.Int64("feed_id", feedID),
|
||||
slog.Any("error", err),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue