-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
142 additions
and
52 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
apps/backend/db/migrations/20240902224247_create_analytics_timeseries.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
-- migrate:up | ||
create table analytics_timeseries ( | ||
query text not null, | ||
occurences int not null, | ||
date timestamptz not null, | ||
primary key (query, date) | ||
); | ||
|
||
-- migrate:down | ||
drop table analytics_timeseries; |
7 changes: 7 additions & 0 deletions
7
apps/backend/db/migrations/20240902225236_alter_default_value_in_search_analytics.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
-- migrate:up | ||
alter table only search_analytics alter column occurences set default 1; | ||
update search_analytics set occurences = occurences + 1; | ||
|
||
-- migrate:down | ||
alter table only search_analytics alter column occurences set default 0; | ||
update search_analytics set occurences = occurences - 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import backend/config.{type Context} | ||
import backend/error | ||
import backend/postgres/queries | ||
import gleam/function | ||
import gleam/list | ||
import gleam/result | ||
import wisp | ||
|
||
pub fn store_timeseries(ctx: Context) { | ||
wisp.log_info("Storing analytics timeseries") | ||
let query = queries.select_last_day_search_analytics(ctx.db) | ||
use analytics <- result.try(query) | ||
use _ <- function.tap({ | ||
result.all({ | ||
use analytic <- list.map(analytics) | ||
queries.upsert_search_analytics_timeseries(ctx.db, analytic) | ||
}) | ||
|> result.map_error(error.debug_log) | ||
}) | ||
wisp.log_info("Storing analytics finished!") | ||
} |