()
| 73 | } |
| 74 | |
| 75 | func (r nodeInfoResolver) Usage() (nodeinfo.Usage, error) { |
| 76 | var collCount, postCount int64 |
| 77 | var activeHalfYear, activeMonth int |
| 78 | var err error |
| 79 | collCount, err = r.db.GetTotalCollections() |
| 80 | if err != nil { |
| 81 | collCount = 0 |
| 82 | } |
| 83 | postCount, err = r.db.GetTotalPosts() |
| 84 | if err != nil { |
| 85 | log.Error("Unable to fetch post counts: %v", err) |
| 86 | } |
| 87 | |
| 88 | if r.cfg.App.PublicStats { |
| 89 | // Display bi-yearly / monthly stats |
| 90 | err = r.db.QueryRow(`SELECT COUNT(*) FROM ( |
| 91 | SELECT DISTINCT collection_id |
| 92 | FROM posts |
| 93 | INNER JOIN collections c |
| 94 | ON collection_id = c.id |
| 95 | WHERE collection_id IS NOT NULL |
| 96 | AND updated > DATE_SUB(NOW(), INTERVAL 6 MONTH)) co`).Scan(&activeHalfYear) |
| 97 | if err != nil { |
| 98 | log.Error("Failed getting 6-month active user stats: %s", err) |
| 99 | } |
| 100 | |
| 101 | err = r.db.QueryRow(`SELECT COUNT(*) FROM ( |
| 102 | SELECT DISTINCT collection_id |
| 103 | FROM posts |
| 104 | INNER JOIN collections c |
| 105 | ON collection_id = c.id |
| 106 | WHERE collection_id IS NOT NULL |
| 107 | AND updated > DATE_SUB(NOW(), INTERVAL 1 MONTH)) co`).Scan(&activeMonth) |
| 108 | if err != nil { |
| 109 | log.Error("Failed getting 1-month active user stats: %s", err) |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | return nodeinfo.Usage{ |
| 114 | Users: nodeinfo.UsageUsers{ |
| 115 | Total: int(collCount), |
| 116 | ActiveHalfYear: activeHalfYear, |
| 117 | ActiveMonth: activeMonth, |
| 118 | }, |
| 119 | LocalPosts: int(postCount), |
| 120 | }, nil |
| 121 | } |
nothing calls this directly
no test coverage detected