Initial sqlite3 compatibility

This commit is contained in:
2018-11-13 00:58:44 +00:00
parent e15ca16d17
commit 80e66d2b32
7 changed files with 123 additions and 170 deletions

View File

@@ -5,6 +5,7 @@ import (
"github.com/writeas/web-core/log"
"github.com/writeas/writefreely/config"
"strings"
"time"
)
type nodeInfoResolver struct {
@@ -67,6 +68,10 @@ func (r nodeInfoResolver) Usage() (nodeinfo.Usage, error) {
log.Error("Unable to fetch post counts: %v", err)
}
ago_1 := time.Now().Add(-(30*24*time.Hour))
ago_6 := time.Now().Add(-(30*24*time.Hour*6))
if r.cfg.App.PublicStats {
// Display bi-yearly / monthly stats
err = r.db.QueryRow(`SELECT COUNT(*) FROM (
@@ -75,7 +80,7 @@ FROM posts
INNER JOIN collections c
ON collection_id = c.id
WHERE collection_id IS NOT NULL
AND updated > DATE_SUB(NOW(), INTERVAL 6 MONTH)) co`).Scan(&activeHalfYear)
AND updated > ? co`, ago_6).Scan(&activeHalfYear)
err = r.db.QueryRow(`SELECT COUNT(*) FROM (
SELECT DISTINCT collection_id
@@ -83,7 +88,7 @@ FROM posts
INNER JOIN FROM collections c
ON collection_id = c.id
WHERE collection_id IS NOT NULL
AND updated > DATE_SUB(NOW(), INTERVAL 1 MONTH)) co`).Scan(&activeMonth)
AND updated > ? co`, ago_1).Scan(&activeMonth)
}
return nodeinfo.Usage{