summaryrefslogtreecommitdiff
path: root/storage/feed.go
diff options
context:
space:
mode:
authorGravatar Frédéric Guillot <f@miniflux.net> 2020-09-27 16:01:06 -0700
committerGravatar Frédéric Guillot <fred@miniflux.net> 2020-09-27 20:04:48 -0700
commitc394a61a4e1fe395191262ed1ccaf70b90a71484 (patch)
treeca3080c4eeb29f3a01d47676be9521334e0696cd /storage/feed.go
parent16b7b3bc3e4237abbacdf8695a685ca9a03dc5bb (diff)
downloadv2-c394a61a4e1fe395191262ed1ccaf70b90a71484.tar.gz
v2-c394a61a4e1fe395191262ed1ccaf70b90a71484.tar.zst
v2-c394a61a4e1fe395191262ed1ccaf70b90a71484.zip
Add Prometheus exporter
Diffstat (limited to 'storage/feed.go')
-rw-r--r--storage/feed.go49
1 files changed, 46 insertions, 3 deletions
diff --git a/storage/feed.go b/storage/feed.go
index 55ce6e83..697ef095 100644
--- a/storage/feed.go
+++ b/storage/feed.go
@@ -76,6 +76,37 @@ func (s *Storage) AnotherFeedURLExists(userID, feedID int64, feedURL string) boo
return result
}
+// CountAllFeeds returns the number of feeds in the database.
+func (s *Storage) CountAllFeeds() map[string]int64 {
+ rows, err := s.db.Query(`SELECT disabled, count(*) FROM feeds GROUP BY disabled`)
+ if err != nil {
+ return nil
+ }
+ defer rows.Close()
+
+ results := make(map[string]int64)
+ results["enabled"] = 0
+ results["disabled"] = 0
+
+ for rows.Next() {
+ var disabled bool
+ var count int64
+
+ if err := rows.Scan(&disabled, &count); err != nil {
+ continue
+ }
+
+ if disabled {
+ results["disabled"] = count
+ } else {
+ results["enabled"] = count
+ }
+ }
+
+ results["total"] = results["disabled"] + results["enabled"]
+ return results
+}
+
// CountFeeds returns the number of feeds that belongs to the given user.
func (s *Storage) CountFeeds(userID int64) int {
var result int
@@ -87,9 +118,9 @@ func (s *Storage) CountFeeds(userID int64) int {
return result
}
-// CountErrorFeeds returns the number of feeds with parse errors that belong to the given user.
-func (s *Storage) CountErrorFeeds(userID int64) int {
- query := `SELECT count(*) FROM feeds WHERE user_id=$1 AND parsing_error_count>=$2`
+// CountUserFeedsWithErrors returns the number of feeds with parsing errors that belong to the given user.
+func (s *Storage) CountUserFeedsWithErrors(userID int64) int {
+ query := `SELECT count(*) FROM feeds WHERE user_id=$1 AND parsing_error_count >= $2`
var result int
err := s.db.QueryRow(query, userID, maxParsingError).Scan(&result)
if err != nil {
@@ -99,6 +130,18 @@ func (s *Storage) CountErrorFeeds(userID int64) int {
return result
}
+// CountAllFeedsWithErrors returns the number of feeds with parsing errors.
+func (s *Storage) CountAllFeedsWithErrors() int {
+ query := `SELECT count(*) FROM feeds WHERE parsing_error_count >= $1`
+ var result int
+ err := s.db.QueryRow(query, maxParsingError).Scan(&result)
+ if err != nil {
+ return 0
+ }
+
+ return result
+}
+
// Feeds returns all feeds that belongs to the given user.
func (s *Storage) Feeds(userID int64) (model.Feeds, error) {
return s.fetchFeeds(feedListQuery, "", userID)