Calculate a virtual weekly count based on the average updating frequency.

This commit is contained in:
Shizun Ge 2023-11-24 01:00:57 -08:00 committed by Frédéric Guillot
parent 27ec6dbd7d
commit bfa83cbf99

View file

@ -162,9 +162,15 @@ func (s *Storage) FeedsByCategoryWithCounters(userID, categoryID int64) (model.F
// WeeklyFeedEntryCount returns the weekly entry count for a feed. // WeeklyFeedEntryCount returns the weekly entry count for a feed.
func (s *Storage) WeeklyFeedEntryCount(userID, feedID int64) (int, error) { func (s *Storage) WeeklyFeedEntryCount(userID, feedID int64) (int, error) {
// Calculate a virtual weekly count based on the average updating frequency.
// This helps after just adding a high volume feed.
// Return 0 when the 'count(*)' is zero(0) or one(1).
query := ` query := `
SELECT SELECT
count(*) COALESCE(CAST(CEIL(
(EXTRACT(epoch from interval '1 week')) /
NULLIF((EXTRACT(epoch from (max(published_at)-min(published_at))/NULLIF((count(*)-1), 0) )), 0)
) AS BIGINT), 0)
FROM FROM
entries entries
WHERE WHERE