diff options
author | Jakob Borg <jakob@kastelo.net> | 2024-01-15 13:11:01 +0100 |
---|---|---|
committer | Jakob Borg <jakob@kastelo.net> | 2024-01-15 13:11:01 +0100 |
commit | 9a24a85ec9c67d3b04e5c7bf5cc93364e45396fa (patch) | |
tree | b2b40da5c1efe4d4c817c89056aff377a0717929 | |
parent | 55a0f4470d637f7db5426e949744b812c6df8157 (diff) |
wip
-rw-r--r-- | cmd/ursrv/aggregate/aggregate.go | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/cmd/ursrv/aggregate/aggregate.go b/cmd/ursrv/aggregate/aggregate.go index 0e7644bfa4..0d7c848260 100644 --- a/cmd/ursrv/aggregate/aggregate.go +++ b/cmd/ursrv/aggregate/aggregate.go @@ -598,7 +598,7 @@ func runMigration(db *sql.DB, store *blob.UrsrvStore, geoIPPath, from, to string // Aggregate the reports of all the days prior to today, as all the usage // reports for those days should be put in the db already. for fromDate.Before(toDate) { - log.Println("migrating", fromDate) + log.Println("migrating", fromDate.Format(time.DateOnly)) // Obtain the reports for the given date from the db. reports, err := reportsFromDB(db, fromDate) @@ -607,9 +607,11 @@ func runMigration(db *sql.DB, store *blob.UrsrvStore, geoIPPath, from, to string } if len(reports) == 0 { // No valid reports were obtained for this date. + log.Println("no reports for", fromDate.Format(time.DateOnly)) fromDate = fromDate.AddDate(0, 0, 1) continue } + log.Println("got", len(reports), "reports for", fromDate.Format(time.DateOnly)) // Aggregate the reports. aggregated, err := aggregateUserReports(geoip, fromDate, reports) @@ -635,8 +637,10 @@ func reportsFromDB(db *sql.DB, date time.Time) ([]contract.Report, error) { var reports []contract.Report // Select all the rows where the received day is equal to the given timestamp's day. + date = date.UTC() + nextDay := date.AddDate(0, 0, 1) rows, err := db.Query(` - SELECT Received, Report FROM ReportsJson WHERE DATE_TRUNC('day', Received) = DATE_TRUNC('day', $1::timestamp)`, date) + SELECT Received, Report FROM ReportsJson WHERE Received >= $1 AND Received < $2`, date, nextDay) if err != nil { return reports, err } @@ -654,6 +658,9 @@ func reportsFromDB(db *sql.DB, date time.Time) ([]contract.Report, error) { } reports = append(reports, rep) } + if rows.Err() != nil { + return reports, rows.Err() + } return reports, nil } |