mirror of https://github.com/status-im/fathom.git
fix pageviews data retrieval for new table structure
This commit is contained in:
parent
963716b1be
commit
f7a1d7ff35
|
@ -13,12 +13,15 @@ import (
|
||||||
var GetPageviewsHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
var GetPageviewsHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
before, after := getRequestedPeriods(r)
|
before, after := getRequestedPeriods(r)
|
||||||
stmt, err := db.Conn.Prepare(`SELECT
|
stmt, err := db.Conn.Prepare(`SELECT
|
||||||
path,
|
s.url,
|
||||||
COUNT(ip_address) AS pageviews,
|
p.path,
|
||||||
COUNT(DISTINCT(ip_address)) AS pageviews_unique
|
COUNT(v.ip_address) AS pageviews,
|
||||||
FROM visits
|
COUNT(DISTINCT(v.ip_address)) AS pageviews_unique
|
||||||
WHERE UNIX_TIMESTAMP(timestamp) <= ? AND UNIX_TIMESTAMP(timestamp) >= ?
|
FROM visits v
|
||||||
GROUP BY path
|
LEFT JOIN pages p ON v.page_id = p.id
|
||||||
|
LEFT JOIN sites s ON p.site_id = s.id
|
||||||
|
WHERE UNIX_TIMESTAMP(v.timestamp) <= ? AND UNIX_TIMESTAMP(timestamp) >= ?
|
||||||
|
GROUP BY p.path, s.url
|
||||||
ORDER BY pageviews DESC
|
ORDER BY pageviews DESC
|
||||||
LIMIT ?`)
|
LIMIT ?`)
|
||||||
checkError(err)
|
checkError(err)
|
||||||
|
@ -31,7 +34,7 @@ var GetPageviewsHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.R
|
||||||
results := make([]models.Pageview, 0)
|
results := make([]models.Pageview, 0)
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var p models.Pageview
|
var p models.Pageview
|
||||||
err = rows.Scan(&p.Path, &p.Count, &p.CountUnique);
|
err = rows.Scan(&p.Url, &p.Path, &p.Count, &p.CountUnique);
|
||||||
checkError(err)
|
checkError(err)
|
||||||
results = append(results, p)
|
results = append(results, p)
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ var screenResolutions = []string {
|
||||||
func seedSite() models.Site {
|
func seedSite() models.Site {
|
||||||
// get first site or create one
|
// get first site or create one
|
||||||
var site models.Site
|
var site models.Site
|
||||||
Conn.QueryRow("SELECT url FROM sites LIMIT 1").Scan(&site.Url)
|
Conn.QueryRow("SELECT id, url FROM sites LIMIT 1").Scan(&site.ID, &site.Url)
|
||||||
|
|
||||||
if site.Url == "" {
|
if site.Url == "" {
|
||||||
site.Url = "http://local.wordpress.dev/"
|
site.Url = "http://local.wordpress.dev/"
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
type Pageview struct {
|
type Pageview struct {
|
||||||
|
Url string
|
||||||
Path string
|
Path string
|
||||||
Count int
|
Count int
|
||||||
CountUnique int
|
CountUnique int
|
||||||
|
|
Loading…
Reference in New Issue