MCPcopy Create free account
hub / github.com/writefreely/writefreely / Usage

Method Usage

nodeinfo.go:75–121  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

73}
74
75func (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 (
91SELECT DISTINCT collection_id
92FROM posts
93INNER JOIN collections c
94ON collection_id = c.id
95WHERE 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 (
102SELECT DISTINCT collection_id
103FROM posts
104INNER JOIN collections c
105ON collection_id = c.id
106WHERE 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}

Callers

nothing calls this directly

Calls 2

GetTotalCollectionsMethod · 0.65
GetTotalPostsMethod · 0.65

Tested by

no test coverage detected