mirror of https://github.com/status-im/fathom.git
and finally, delete pageviews after processing to keep pageviews table nice & small
This commit is contained in:
parent
95cd0e4053
commit
5e0ac22fe4
|
@ -43,7 +43,6 @@ class Table extends Component {
|
|||
|
||||
Client.request(`${this.props.endpoint}?before=${this.state.before}&after=${this.state.after}&limit=${this.state.limit}`)
|
||||
.then((d) => {
|
||||
console.log(d);
|
||||
this.setState({
|
||||
loading: false,
|
||||
records: d,
|
||||
|
|
|
@ -99,6 +99,7 @@ func Aggregate() error {
|
|||
|
||||
}
|
||||
|
||||
// update stats
|
||||
err = datastore.UpdateSiteStats(siteStats)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
|
@ -121,7 +122,12 @@ func Aggregate() error {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: delete data
|
||||
// finally, remove pageviews that we just processed
|
||||
err = datastore.DeletePageviews(pageviews)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -2,8 +2,11 @@ package datastore
|
|||
|
||||
import (
|
||||
"database/sql"
|
||||
"github.com/usefathom/fathom/pkg/models"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/usefathom/fathom/pkg/models"
|
||||
)
|
||||
|
||||
// SavePageview inserts a single pageview model into the connected database
|
||||
|
@ -48,3 +51,13 @@ func GetProcessablePageviews() ([]*models.Pageview, error) {
|
|||
err := dbx.Select(&results, query, thirtyMinsAgo, fiveMinsAgo)
|
||||
return results, err
|
||||
}
|
||||
|
||||
func DeletePageviews(pageviews []*models.Pageview) error {
|
||||
ids := []string{}
|
||||
for _, p := range pageviews {
|
||||
ids = append(ids, strconv.FormatInt(p.ID, 10))
|
||||
}
|
||||
query := dbx.Rebind(`DELETE FROM pageviews WHERE id IN(` + strings.Join(ids, ",") + `)`)
|
||||
_, err := dbx.Exec(query)
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue