mirror of
https://github.com/miniflux/v2.git
synced 2025-08-26 18:21:01 +00:00
feat(storage): add limit parameter to ClearRemovedEntriesContent
Without the limit, this query is going to hangs forever on large databases with millions of entries.
This commit is contained in:
parent
905d652511
commit
5403ca09f6
2 changed files with 13 additions and 6 deletions
|
@ -54,7 +54,7 @@ func runCleanupTasks(store *storage.Storage) {
|
||||||
slog.Int64("removed_entries_enclosures_deleted", enclosuresAffected))
|
slog.Int64("removed_entries_enclosures_deleted", enclosuresAffected))
|
||||||
}
|
}
|
||||||
|
|
||||||
if contentAffected, err := store.ClearRemovedEntriesContent(); err != nil {
|
if contentAffected, err := store.ClearRemovedEntriesContent(config.Opts.CleanupArchiveBatchSize()); err != nil {
|
||||||
slog.Error("Unable to clear content from removed entries", slog.Any("error", err))
|
slog.Error("Unable to clear content from removed entries", slog.Any("error", err))
|
||||||
} else {
|
} else {
|
||||||
slog.Info("Clearing content from removed entries completed",
|
slog.Info("Clearing content from removed entries completed",
|
||||||
|
|
|
@ -297,7 +297,7 @@ func (s *Storage) DeleteRemovedEntriesEnclosures() (int64, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClearRemovedEntriesContent clears the content fields of entries marked as "removed", keeping only their metadata.
|
// ClearRemovedEntriesContent clears the content fields of entries marked as "removed", keeping only their metadata.
|
||||||
func (s *Storage) ClearRemovedEntriesContent() (int64, error) {
|
func (s *Storage) ClearRemovedEntriesContent(limit int) (int64, error) {
|
||||||
query := `
|
query := `
|
||||||
UPDATE
|
UPDATE
|
||||||
entries
|
entries
|
||||||
|
@ -305,12 +305,19 @@ func (s *Storage) ClearRemovedEntriesContent() (int64, error) {
|
||||||
title='',
|
title='',
|
||||||
content=NULL,
|
content=NULL,
|
||||||
url='',
|
url='',
|
||||||
author=NULL
|
author=NULL,
|
||||||
WHERE
|
comments_url=NULL,
|
||||||
status=$1 AND content IS NOT NULL
|
document_vectors=NULL
|
||||||
|
WHERE id IN (
|
||||||
|
SELECT id
|
||||||
|
FROM entries
|
||||||
|
WHERE status = $1 AND content IS NOT NULL
|
||||||
|
ORDER BY id ASC
|
||||||
|
LIMIT $2
|
||||||
|
)
|
||||||
`
|
`
|
||||||
|
|
||||||
result, err := s.db.Exec(query, model.EntryStatusRemoved)
|
result, err := s.db.Exec(query, model.EntryStatusRemoved, limit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, fmt.Errorf(`store: unable to clear content from removed entries: %v`, err)
|
return 0, fmt.Errorf(`store: unable to clear content from removed entries: %v`, err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue