From d4afc42d5c8a5a3ba9357eae6e8c831c8763e449 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Sat, 9 Jul 2022 13:16:32 -0400 Subject: [PATCH] Index on tts results creation date, query on popular models by date --- .../down.sql | 5 +++++ .../up.sql | 5 +++++ analytics/most_popular_tts_models_time_period.sql | 12 ++++++++++++ 3 files changed, 22 insertions(+) create mode 100644 _migrations/2022-07-09-170014_tts_results_creation_index/down.sql create mode 100644 _migrations/2022-07-09-170014_tts_results_creation_index/up.sql create mode 100644 analytics/most_popular_tts_models_time_period.sql diff --git a/_migrations/2022-07-09-170014_tts_results_creation_index/down.sql b/_migrations/2022-07-09-170014_tts_results_creation_index/down.sql new file mode 100644 index 0000000000..5f8de8d4ac --- /dev/null +++ b/_migrations/2022-07-09-170014_tts_results_creation_index/down.sql @@ -0,0 +1,5 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile +-- noinspection SqlResolveForFile + +DROP INDEX `index_created_at` ON `tts_results`; diff --git a/_migrations/2022-07-09-170014_tts_results_creation_index/up.sql b/_migrations/2022-07-09-170014_tts_results_creation_index/up.sql new file mode 100644 index 0000000000..fbc363e626 --- /dev/null +++ b/_migrations/2022-07-09-170014_tts_results_creation_index/up.sql @@ -0,0 +1,5 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile +-- noinspection SqlResolveForFile + +CREATE INDEX `index_created_at` ON `tts_results` (`created_at`); \ No newline at end of file diff --git a/analytics/most_popular_tts_models_time_period.sql b/analytics/most_popular_tts_models_time_period.sql new file mode 100644 index 0000000000..4e565d6fab --- /dev/null +++ b/analytics/most_popular_tts_models_time_period.sql @@ -0,0 +1,12 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile +-- noinspection SqlResolveForFile + +select m.token, m.title, r.use_count from ( + select model_token, count(*) as use_count from tts_results + where created_at < now() - interval 30 day + group by model_token + order by use_count desc limit 100 +) as r + join tts_models as m + on m.token = r.model_token; \ No newline at end of file