Calculate a virtual weekly count based on the average updating frequency.
This commit is contained in:
parent
27ec6dbd7d
commit
bfa83cbf99
1 changed files with 7 additions and 1 deletions
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue