mirror of
https://github.com/idanoo/go-mastodon-stats
synced 2025-07-01 13:52: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 {
|
||||
monday := getStartofDayMonday()
|
||||
log.Printf(
|
||||
"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(
|
||||
val, err := runIntQueryWithTime(
|
||||
POSTGRESQL_STATS_DB,
|
||||
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,
|
||||
METRICNAME_USERCOUNT,
|
||||
serviceName,
|
||||
monday,
|
||||
),
|
||||
monday,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
|
|
|
@ -3,6 +3,7 @@ package gomastodonstats
|
|||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
_ "github.com/lib/pq"
|
||||
)
|
||||
|
@ -57,3 +58,23 @@ func runIntQuery(schema string, q string) (int, error) {
|
|||
|
||||
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