diff options
Diffstat (limited to 'internal/storage')
-rw-r--r-- | internal/storage/category.go | 10 | ||||
-rw-r--r-- | internal/storage/entry.go | 35 | ||||
-rw-r--r-- | internal/storage/entry_pagination_builder.go | 4 | ||||
-rw-r--r-- | internal/storage/feed.go | 9 | ||||
-rw-r--r-- | internal/storage/user.go | 18 |
5 files changed, 53 insertions, 23 deletions
diff --git a/internal/storage/category.go b/internal/storage/category.go index 5ee8404b..285b3f97 100644 --- a/internal/storage/category.go +++ b/internal/storage/category.go @@ -238,7 +238,7 @@ func (s *Storage) RemoveCategory(userID, categoryID int64) error { func (s *Storage) RemoveAndReplaceCategoriesByName(userid int64, titles []string) error { tx, err := s.db.Begin() if err != nil { - return errors.New("unable to begin transaction") + return errors.New("store: unable to begin transaction") } titleParam := pq.Array(titles) @@ -247,11 +247,11 @@ func (s *Storage) RemoveAndReplaceCategoriesByName(userid int64, titles []string err = tx.QueryRow(query, userid, titleParam).Scan(&count) if err != nil { tx.Rollback() - return errors.New("unable to retrieve category count") + return errors.New("store: unable to retrieve category count") } if count < 1 { tx.Rollback() - return errors.New("at least 1 category must remain after deletion") + return errors.New("store: at least 1 category must remain after deletion") } query = ` @@ -268,14 +268,14 @@ func (s *Storage) RemoveAndReplaceCategoriesByName(userid int64, titles []string _, err = tx.Exec(query, userid, titleParam) if err != nil { tx.Rollback() - return fmt.Errorf("unable to replace categories: %v", err) + return fmt.Errorf("store: unable to replace categories: %v", err) } query = "DELETE FROM categories WHERE user_id = $1 AND title = ANY($2)" _, err = tx.Exec(query, userid, titleParam) if err != nil { tx.Rollback() - return fmt.Errorf("unable to delete categories: %v", err) + return fmt.Errorf("store: unable to delete categories: %v", err) } tx.Commit() return nil diff --git a/internal/storage/entry.go b/internal/storage/entry.go index 718f50d1..e36646b4 100644 --- a/internal/storage/entry.go +++ b/internal/storage/entry.go @@ -7,10 +7,10 @@ import ( "database/sql" "errors" "fmt" + "log/slog" "time" "miniflux.app/v2/internal/crypto" - "miniflux.app/v2/internal/logger" "miniflux.app/v2/internal/model" "github.com/lib/pq" @@ -52,7 +52,10 @@ func (s *Storage) CountUnreadEntries(userID int64) int { n, err := builder.CountEntries() if err != nil { - logger.Error(`store: unable to count unread entries for user #%d: %v`, userID, err) + slog.Error("Unable to count unread entries", + slog.Int64("user_id", userID), + slog.Any("error", err), + ) return 0 } @@ -316,7 +319,11 @@ func (s *Storage) RefreshFeedEntries(userID, feedID int64, entries model.Entries go func() { if err := s.cleanupEntries(feedID, entryHashes); err != nil { - logger.Error(`store: feed #%d: %v`, feedID, err) + slog.Error("Unable to cleanup entries", + slog.Int64("user_id", userID), + slog.Int64("feed_id", feedID), + slog.Any("error", err), + ) } }() @@ -463,7 +470,10 @@ func (s *Storage) MarkAllAsRead(userID int64) error { } count, _ := result.RowsAffected() - logger.Debug("[Storage:MarkAllAsRead] %d items marked as read", count) + slog.Debug("Marked all entries as read", + slog.Int64("user_id", userID), + slog.Int64("nb_entries", count), + ) return nil } @@ -490,7 +500,10 @@ func (s *Storage) MarkGloballyVisibleFeedsAsRead(userID int64) error { } count, _ := result.RowsAffected() - logger.Debug("[Storage:MarkGloballyVisibleFeedsAsRead] %d items marked as read", count) + slog.Debug("Marked globally visible feed entries as read", + slog.Int64("user_id", userID), + slog.Int64("nb_entries", count), + ) return nil } @@ -512,7 +525,11 @@ func (s *Storage) MarkFeedAsRead(userID, feedID int64, before time.Time) error { } count, _ := result.RowsAffected() - logger.Debug("[Storage:MarkFeedAsRead] %d items marked as read", count) + slog.Debug("Marked feed entries as read", + slog.Int64("user_id", userID), + slog.Int64("feed_id", feedID), + slog.Int64("nb_entries", count), + ) return nil } @@ -540,7 +557,11 @@ func (s *Storage) MarkCategoryAsRead(userID, categoryID int64, before time.Time) } count, _ := result.RowsAffected() - logger.Debug("[Storage:MarkCategoryAsRead] %d items marked as read", count) + slog.Debug("Marked category entries as read", + slog.Int64("user_id", userID), + slog.Int64("category_id", categoryID), + slog.Int64("nb_entries", count), + ) return nil } diff --git a/internal/storage/entry_pagination_builder.go b/internal/storage/entry_pagination_builder.go index b4f77c8c..bab478d3 100644 --- a/internal/storage/entry_pagination_builder.go +++ b/internal/storage/entry_pagination_builder.go @@ -7,10 +7,8 @@ import ( "database/sql" "fmt" "strings" - "time" "miniflux.app/v2/internal/model" - "miniflux.app/v2/internal/timer" ) // EntryPaginationBuilder is a builder for entry prev/next queries. @@ -101,8 +99,6 @@ func (e *EntryPaginationBuilder) Entries() (*model.Entry, *model.Entry, error) { } func (e *EntryPaginationBuilder) getPrevNextID(tx *sql.Tx) (prevID int64, nextID int64, err error) { - defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[EntryPaginationBuilder] %v, %v", e.conditions, e.args)) - cte := ` WITH entry_pagination AS ( SELECT diff --git a/internal/storage/feed.go b/internal/storage/feed.go index 5cf32181..b7f52e65 100644 --- a/internal/storage/feed.go +++ b/internal/storage/feed.go @@ -7,11 +7,10 @@ import ( "database/sql" "errors" "fmt" - "runtime" + "log/slog" "sort" "miniflux.app/v2/internal/config" - "miniflux.app/v2/internal/logger" "miniflux.app/v2/internal/model" ) @@ -432,7 +431,11 @@ func (s *Storage) RemoveFeed(userID, feedID int64) error { return fmt.Errorf(`store: unable to read user feed entry ID: %v`, err) } - logger.Debug(`[FEED DELETION] Deleting entry #%d of feed #%d for user #%d (%d GoRoutines)`, entryID, feedID, userID, runtime.NumGoroutine()) + slog.Debug("Deleting entry", + slog.Int64("user_id", userID), + slog.Int64("feed_id", feedID), + slog.Int64("entry_id", entryID), + ) if _, err := s.db.Exec(`DELETE FROM entries WHERE id=$1 AND user_id=$2`, entryID, userID); err != nil { return fmt.Errorf(`store: unable to delete user feed entries #%d: %v`, entryID, err) diff --git a/internal/storage/user.go b/internal/storage/user.go index 0c5fcad0..bde2bf15 100644 --- a/internal/storage/user.go +++ b/internal/storage/user.go @@ -6,11 +6,11 @@ package storage // import "miniflux.app/v2/internal/storage" import ( "database/sql" "fmt" + "log/slog" "runtime" "strings" "miniflux.app/v2/internal/crypto" - "miniflux.app/v2/internal/logger" "miniflux.app/v2/internal/model" "github.com/lib/pq" @@ -506,14 +506,20 @@ func (s *Storage) RemoveUser(userID int64) error { func (s *Storage) RemoveUserAsync(userID int64) { go func() { if err := s.deleteUserFeeds(userID); err != nil { - logger.Error(`%v`, err) + slog.Error("Unable to delete user feedd", + slog.Int64("user_id", userID), + slog.Any("error", err), + ) return } s.db.Exec(`DELETE FROM users WHERE id=$1`, userID) s.db.Exec(`DELETE FROM integrations WHERE user_id=$1`, userID) - logger.Debug(`[MASS DELETE] User #%d has been deleted (%d GoRoutines)`, userID, runtime.NumGoroutine()) + slog.Debug("User deleted", + slog.Int64("user_id", userID), + slog.Int("goroutines", runtime.NumGoroutine()), + ) }() } @@ -528,7 +534,11 @@ func (s *Storage) deleteUserFeeds(userID int64) error { var feedID int64 rows.Scan(&feedID) - logger.Debug(`[USER DELETION] Deleting feed #%d for user #%d (%d GoRoutines)`, feedID, userID, runtime.NumGoroutine()) + slog.Debug("Deleting feed", + slog.Int64("user_id", userID), + slog.Int64("feed_id", feedID), + slog.Int("goroutines", runtime.NumGoroutine()), + ) if err := s.RemoveFeed(userID, feedID); err != nil { return err |