diff --git a/VERSION b/VERSION index 870aec4a7..892666608 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.79.0 +0.79.1 diff --git a/appmetrics/database.go b/appmetrics/database.go index a96ac65da..6b8259c12 100644 --- a/appmetrics/database.go +++ b/appmetrics/database.go @@ -28,6 +28,11 @@ type AppMetricValidationError struct { Errors []gojsonschema.ResultError } +type Page struct { + AppMetrics []AppMetric + TotalCount int +} + const ( // status-react navigation events NavigateTo AppMetricEventType = "navigate-to" @@ -140,13 +145,18 @@ func (db *Database) SaveAppMetrics(appMetrics []AppMetric, sessionID string) (er return } -func (db *Database) GetAppMetrics(limit int, offset int) (appMetrics []AppMetric, err error) { - rows, err := db.db.Query("SELECT event, value, app_version, operating_system, session_id, created_at FROM app_metrics LIMIT ? OFFSET ?", limit, offset) +func (db *Database) GetAppMetrics(limit int, offset int) (page Page, err error) { + countErr := db.db.QueryRow("SELECT count(*) FROM app_metrics").Scan(&page.TotalCount) + if countErr != nil { + return page, countErr + } + rows, err := db.db.Query("SELECT event, value, app_version, operating_system, session_id, created_at FROM app_metrics LIMIT ? OFFSET ?", limit, offset) if err != nil { - return nil, err + return page, err } defer rows.Close() + for rows.Next() { metric := AppMetric{} err := rows.Scan( @@ -155,9 +165,9 @@ func (db *Database) GetAppMetrics(limit int, offset int) (appMetrics []AppMetric &metric.SessionID, &metric.CreatedAt, ) if err != nil { - return nil, err + return page, err } - appMetrics = append(appMetrics, metric) + page.AppMetrics = append(page.AppMetrics, metric) } - return appMetrics, nil + return page, nil } diff --git a/appmetrics/database_test.go b/appmetrics/database_test.go index 26a428c8a..df7888c67 100644 --- a/appmetrics/database_test.go +++ b/appmetrics/database_test.go @@ -37,11 +37,14 @@ func TestSaveAppMetrics(t *testing.T) { err := db.SaveAppMetrics(appMetrics, sessionID) require.NoError(t, err) - res, err := db.GetAppMetrics(10, 0) + appMetricsPage, err := db.GetAppMetrics(10, 0) + res := appMetricsPage.AppMetrics + count := appMetricsPage.TotalCount require.NoError(t, err) require.Equal(t, appMetrics[0].Event, res[0].Event) require.Equal(t, appMetrics[0].Value, res[0].Value) require.Equal(t, appMetrics[0].OS, res[0].OS) require.Equal(t, appMetrics[0].AppVersion, res[0].AppVersion) require.NotNil(t, res[0].CreatedAt) + require.Equal(t, count, 1) } diff --git a/services/appmetrics/api.go b/services/appmetrics/api.go index 2d937a262..f294736b9 100644 --- a/services/appmetrics/api.go +++ b/services/appmetrics/api.go @@ -28,7 +28,7 @@ func (api *API) SaveAppMetrics(ctx context.Context, appMetrics []appmetrics.AppM return api.db.SaveAppMetrics(appMetrics, api.sessionID) } -func (api *API) GetAppMetrics(ctx context.Context, limit int, offset int) ([]appmetrics.AppMetric, error) { +func (api *API) GetAppMetrics(ctx context.Context, limit int, offset int) (appmetrics.Page, error) { log.Debug("[AppMetricsAPI::GetAppMetrics]") return api.db.GetAppMetrics(limit, offset) }