diff --git a/backend/src/app/migrations.clj b/backend/src/app/migrations.clj index 965b0ce77..2a4728c8e 100644 --- a/backend/src/app/migrations.clj +++ b/backend/src/app/migrations.clj @@ -391,7 +391,10 @@ :fn (mg/resource "app/migrations/sql/0122-mod-file-data-fragment-table.sql")} {:name "0123-mod-file-change-table" - :fn (mg/resource "app/migrations/sql/0123-mod-file-change-table.sql")}]) + :fn (mg/resource "app/migrations/sql/0123-mod-file-change-table.sql")} + + {:name "0124-mod-profile-table" + :fn (mg/resource "app/migrations/sql/0124-mod-profile-table.sql")}]) (defn apply-migrations! [pool name migrations] diff --git a/backend/src/app/migrations/sql/0124-mod-profile-table.sql b/backend/src/app/migrations/sql/0124-mod-profile-table.sql new file mode 100644 index 000000000..e9624abd6 --- /dev/null +++ b/backend/src/app/migrations/sql/0124-mod-profile-table.sql @@ -0,0 +1,2 @@ +CREATE INDEX profile__props__newsletter1__idx ON profile (email) WHERE props->>'~:newsletter-news' = 'true'; +CREATE INDEX profile__props__newsletter2__idx ON profile (email) WHERE props->>'~:newsletter-updates' = 'true'; diff --git a/backend/src/app/tasks/telemetry.clj b/backend/src/app/tasks/telemetry.clj index 410595f72..204d6be0c 100644 --- a/backend/src/app/tasks/telemetry.clj +++ b/backend/src/app/tasks/telemetry.clj @@ -62,19 +62,25 @@ [conn] (-> (db/exec-one! conn ["SELECT count(*) AS count FROM file"]) :count)) +(def ^:private sql:num-file-changes + "SELECT count(*) AS count + FROM file_change + WHERE created_at < date_trunc('day', now()) + '24 hours'::interval + AND created_at > date_trunc('day', now())") + (defn- get-num-file-changes [conn] - (let [sql (str "SELECT count(*) AS count " - " FROM file_change " - " where date_trunc('day', created_at) = date_trunc('day', now())")] - (-> (db/exec-one! conn [sql]) :count))) + (-> (db/exec-one! conn [sql:num-file-changes]) :count)) + +(def ^:private sql:num-touched-files + "SELECT count(distinct file_id) AS count + FROM file_change + WHERE created_at < date_trunc('day', now()) + '24 hours'::interval + AND created_at > date_trunc('day', now())") (defn- get-num-touched-files [conn] - (let [sql (str "SELECT count(distinct file_id) AS count " - " FROM file_change " - " where date_trunc('day', created_at) = date_trunc('day', now())")] - (-> (db/exec-one! conn [sql]) :count))) + (-> (db/exec-one! conn [sql:num-touched-files]) :count)) (defn- get-num-users [conn]