mirror of
https://github.com/idanoo/go-mastodon-stats
synced 2025-07-01 22:02:20 +00:00
Testing
This commit is contained in:
parent
adfcf44890
commit
6b6037f735
2 changed files with 24 additions and 10 deletions
|
@ -162,22 +162,15 @@ func getLastMetric(serviceName string) int {
|
||||||
|
|
||||||
func getLastWeekMetric(serviceName string) int {
|
func getLastWeekMetric(serviceName string) int {
|
||||||
monday := getStartofDayMonday()
|
monday := getStartofDayMonday()
|
||||||
log.Printf(
|
val, err := runIntQueryWithTime(
|
||||||
"SELECT metric_value FROM %s WHERE metric_name = '%s' AND service = '%s' AND metric_time = '%s' LIMIT 1",
|
|
||||||
POSTGRESQL_STATS_TABLE,
|
|
||||||
METRICNAME_USERCOUNT,
|
|
||||||
serviceName,
|
|
||||||
monday,
|
|
||||||
)
|
|
||||||
val, err := runIntQuery(
|
|
||||||
POSTGRESQL_STATS_DB,
|
POSTGRESQL_STATS_DB,
|
||||||
fmt.Sprintf(
|
fmt.Sprintf(
|
||||||
"SELECT metric_value FROM %s WHERE metric_name = '%s' AND service = '%s' AND metric_time = '%s' LIMIT 1",
|
"SELECT metric_value FROM %s WHERE metric_name = '%s' AND service = '%s' AND metric_time = '$1' LIMIT 1",
|
||||||
POSTGRESQL_STATS_TABLE,
|
POSTGRESQL_STATS_TABLE,
|
||||||
METRICNAME_USERCOUNT,
|
METRICNAME_USERCOUNT,
|
||||||
serviceName,
|
serviceName,
|
||||||
monday,
|
|
||||||
),
|
),
|
||||||
|
monday,
|
||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package gomastodonstats
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
_ "github.com/lib/pq"
|
_ "github.com/lib/pq"
|
||||||
)
|
)
|
||||||
|
@ -57,3 +58,23 @@ func runIntQuery(schema string, q string) (int, error) {
|
||||||
|
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func runIntQueryWithTime(schema string, q string, t time.Time) (int, error) {
|
||||||
|
var res int
|
||||||
|
db, err := getConnection(schema)
|
||||||
|
if err != nil {
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
|
||||||
|
rows, err := db.Query(q, t)
|
||||||
|
if err != nil {
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
|
||||||
|
for rows.Next() {
|
||||||
|
rows.Scan(&res)
|
||||||
|
}
|
||||||
|
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue