2017-12-30 05:47:46 +00:00
package common
// EXPERIMENTAL
import (
2022-02-21 03:32:53 +00:00
"errors"
2017-12-30 05:47:46 +00:00
)
var StatStore StatStoreInt
type StatStoreInt interface {
2022-02-21 03:32:53 +00:00
LookupInt ( name string , duration int , unit string ) ( int , error )
2017-12-30 05:47:46 +00:00
}
type DefaultStatStore struct {
}
func NewDefaultStatStore ( ) * DefaultStatStore {
2022-02-21 03:32:53 +00:00
return & DefaultStatStore { }
2017-12-30 05:47:46 +00:00
}
2019-09-29 04:56:39 +00:00
func ( s * DefaultStatStore ) LookupInt ( name string , duration int , unit string ) ( int , error ) {
2022-02-21 03:32:53 +00:00
switch name {
case "postCount" :
return s . countTable ( "replies" , duration , unit )
}
return 0 , errors . New ( "The requested stat doesn't exist" )
2017-12-30 05:47:46 +00:00
}
2019-09-29 04:56:39 +00:00
func ( s * DefaultStatStore ) countTable ( table string , duration int , unit string ) ( stat int , err error ) {
2022-02-21 03:32:53 +00:00
/ * counter := qgen . NewAcc ( ) . Count ( "replies" ) . DateCutoff ( "createdAt" , 1 , "day" ) . Prepare ( )
if acc . FirstError ( ) != nil {
return 0 , acc . FirstError ( )
}
err := counter . QueryRow ( ) . Scan ( & stat ) * /
return stat , err
2017-12-30 05:47:46 +00:00
}
//stmts.todaysPostCount, err = db.Prepare("select count(*) from replies where createdAt BETWEEN (utc_timestamp() - interval 1 day) and utc_timestamp()")