mirror of https://github.com/status-im/fathom.git
return 0 when archive tables have no rows for given timestamps
This commit is contained in:
parent
c9c30557db
commit
df4843e4cc
|
@ -10,7 +10,7 @@ func TotalUniqueBrowsers(before int64, after int64) int {
|
|||
|
||||
stmt, err := db.Conn.Prepare(`
|
||||
SELECT
|
||||
SUM(t.count_unique)
|
||||
IFNULL( SUM(t.count_unique), 0 )
|
||||
FROM total_browser_names t
|
||||
WHERE UNIX_TIMESTAMP(t.date) <= ? AND UNIX_TIMESTAMP(t.date) >= ?`)
|
||||
checkError(err)
|
||||
|
|
|
@ -10,7 +10,7 @@ func TotalUniqueLanguages(before int64, after int64) int {
|
|||
|
||||
stmt, err := db.Conn.Prepare(`
|
||||
SELECT
|
||||
SUM(t.count_unique)
|
||||
IFNULL( SUM(t.count_unique), 0 )
|
||||
FROM total_browser_languages t
|
||||
WHERE UNIX_TIMESTAMP(t.date) <= ? AND UNIX_TIMESTAMP(t.date) >= ?`)
|
||||
checkError(err)
|
||||
|
|
|
@ -3,16 +3,18 @@ package count
|
|||
import "github.com/dannyvankooten/ana/db"
|
||||
|
||||
// Pageviews returns the total number of pageviews between the given timestamps
|
||||
func Pageviews(before int64, after int64) float64 {
|
||||
func Pageviews(before int64, after int64) int {
|
||||
var total int
|
||||
|
||||
// get total
|
||||
stmt, err := db.Conn.Prepare(`
|
||||
SELECT
|
||||
SUM(t.count)
|
||||
IFNULL( SUM(t.count), 0 )
|
||||
FROM total_pageviews t
|
||||
WHERE UNIX_TIMESTAMP(t.date) <= ? AND UNIX_TIMESTAMP(t.date) >= ?`)
|
||||
checkError(err)
|
||||
defer stmt.Close()
|
||||
var total float64
|
||||
|
||||
stmt.QueryRow(before, after).Scan(&total)
|
||||
return total
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ func TotalReferrers(before int64, after int64) int {
|
|||
|
||||
stmt, err := db.Conn.Prepare(`
|
||||
SELECT
|
||||
SUM(t.count)
|
||||
IFNULL( SUM(t.count), 0 )
|
||||
FROM total_referrers t
|
||||
WHERE UNIX_TIMESTAMP(t.date) <= ? AND UNIX_TIMESTAMP(t.date) >= ?`)
|
||||
checkError(err)
|
||||
|
|
|
@ -10,7 +10,7 @@ func TotalUniqueScreens(before int64, after int64) int {
|
|||
|
||||
stmt, err := db.Conn.Prepare(`
|
||||
SELECT
|
||||
SUM(t.count_unique)
|
||||
IFNULL( SUM(t.count_unique), 0 )
|
||||
FROM total_screens t
|
||||
WHERE UNIX_TIMESTAMP(t.date) <= ? AND UNIX_TIMESTAMP(t.date) >= ?`)
|
||||
checkError(err)
|
||||
|
|
|
@ -15,7 +15,7 @@ func RealtimeVisitors() int {
|
|||
}
|
||||
|
||||
// Visitors returns the number of total visitors between the given timestamps
|
||||
func Visitors(before int64, after int64) float64 {
|
||||
func Visitors(before int64, after int64) int {
|
||||
// get total
|
||||
stmt, err := db.Conn.Prepare(`
|
||||
SELECT
|
||||
|
@ -24,7 +24,7 @@ func Visitors(before int64, after int64) float64 {
|
|||
WHERE UNIX_TIMESTAMP(t.date) <= ? AND UNIX_TIMESTAMP(t.date) >= ?`)
|
||||
checkError(err)
|
||||
defer stmt.Close()
|
||||
var total float64
|
||||
var total int
|
||||
stmt.QueryRow(before, after).Scan(&total)
|
||||
return total
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue