From 8da66a8463c77551aeeca3139a192b153fd928c3 Mon Sep 17 00:00:00 2001 From: Keagan Date: Fri, 10 Jul 2026 11:43:04 +0200 Subject: [PATCH 1/2] added default post number for slack bot --- src/source/routes/slack.clj | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/source/routes/slack.clj b/src/source/routes/slack.clj index aa0884f7..7ed303c2 100644 --- a/src/source/routes/slack.clj +++ b/src/source/routes/slack.clj @@ -32,5 +32,6 @@ :bundle-id state :channel-id channel-id :access-token access-token - :post-interval (* 1000 60 60 24)}) + :post-interval (* 1000 60 60 24) + :posts 4}) (res/response {:message "successfully added channel"}))) From 516646598ae5c51bbe1aeedc8be313f891a25929 Mon Sep 17 00:00:00 2001 From: Keagan Date: Thu, 16 Jul 2026 11:33:13 +0200 Subject: [PATCH 2/2] added selected events to track when posts are selected to make it into a bundle --- src/source/jobs/handlers.clj | 5 ++- src/source/migrations/027_events_check.clj | 23 +++++++++++++ src/source/services/analytics/core.clj | 38 ++++++++++++++++++++- src/source/services/analytics/interface.clj | 9 +++++ 4 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 src/source/migrations/027_events_check.clj diff --git a/src/source/jobs/handlers.clj b/src/source/jobs/handlers.clj index 047a9df3..bcb7ccd3 100644 --- a/src/source/jobs/handlers.clj +++ b/src/source/jobs/handlers.clj @@ -12,7 +12,8 @@ [source.db.honey :as hon] [taoensso.telemere :as t] [source.workers.bundles :as bundles] - [pg.core :as pg])) + [pg.core :as pg] + [source.services.analytics.interface :as analytics])) (defmulti handler (fn [opts] @@ -180,6 +181,8 @@ (hon/delete! ds (db.util/tname :outgoing-posts bundle-id)) (hon/insert! ds (-> (db.util/tname :outgoing-posts bundle-id) (assoc :data outgoing-posts)))) + (analytics/insert-selected-events! ds outgoing-posts bundle-id) + (when (< (count outgoing-posts) 10) (throw (t/error! diff --git a/src/source/migrations/027_events_check.clj b/src/source/migrations/027_events_check.clj new file mode 100644 index 00000000..e2fb319d --- /dev/null +++ b/src/source/migrations/027_events_check.clj @@ -0,0 +1,23 @@ +(ns source.migrations.027-events-check + (:require [source.db.master] + [pg.core :as pg])) + +(defn run-up! [context] + (let [ds-master (:db-master context)] + (pg/execute + ds-master + "ALTER TABLE events + DROP CONSTRAINT IF EXISTS events_event_check"))) + +(defn run-down! [context] + (let [ds-master (:db-master context)] + (pg/with-transaction [ds-master ds-master] + (pg/execute + ds-master + "ALTER TABLE events + DROP CONSTRAINT IF EXISTS events_event_check") + (pg/execute + ds-master + "ALTER TABLE events + ADD CONSTRAINT events_event_check + CHECK (event IN ('impression', 'click', 'view', 'bot_post'))")))) diff --git a/src/source/services/analytics/core.clj b/src/source/services/analytics/core.clj index f4420958..f6531463 100644 --- a/src/source/services/analytics/core.clj +++ b/src/source/services/analytics/core.clj @@ -424,6 +424,36 @@ :ret :*})] (insert-post-event-categories! ds event' post)))) +(defn insert-selected-event! [ds {:keys [id feed-id content-type-id creator-id] :as post} bundle-id] + (pg/with-transaction [ds ds] + (let [bundle (bundles/bundle ds {:id bundle-id}) + event {:timestamp (util/get-utc-timestamp-string) + :event "selected" + :feed-id feed-id + :post-id id + :content-type-id content-type-id + :creator-id creator-id + :bundle-id bundle-id + :distributor-id (:user-id bundle)}] + (insert-event! ds {:data event})))) + +(defn insert-selected-events! + "Given a list of posts and a bundle id, inserts selected event reconds + for each given post. Inserts event categories for each post." + [ds posts bundle-id] + (pg/with-transaction [ds ds] + (let [bundle (bundles/bundle ds {:id bundle-id}) + events (mapv (fn [{:keys [id feed-id content-type-id creator-id]}] + {:timestamp (util/get-utc-timestamp-string) + :event "selected" + :feed-id feed-id + :post-id id + :content-type-id content-type-id + :creator-id creator-id + :bundle-id bundle-id + :distributor-id (:user-id bundle)}) posts)] + (when (seq posts) (insert-event! ds {:data events}))))) + (comment (require '[source.db.util :as db.util]) @@ -572,5 +602,11 @@ :ret :*} {:content-type-id 3})) - ()) + (hon/execute! + ds + (-> (hsql/select [[:count :*]]) + (hsql/from :events) + (hsql/where [:= :event "selected"])) + {:ret :*}) + ()) diff --git a/src/source/services/analytics/interface.clj b/src/source/services/analytics/interface.clj index f56ef000..b2fa44ea 100644 --- a/src/source/services/analytics/interface.clj +++ b/src/source/services/analytics/interface.clj @@ -125,3 +125,12 @@ "Returns a paginated list of the best performing posts on the system in terms of impressions, clicks and views" [ds {:keys [_start _limit] :as opts}] (core/top-post-statistics ds opts)) + +(defn insert-selected-event! [ds {:keys [_id _feed-id _content-type-id _creator-id] :as post} bundle-id] + (core/insert-selected-event! ds post bundle-id)) + +(defn insert-selected-events! + "Given a list of posts and a bundle id, inserts selected event reconds + for each given post. Inserts event categories for each post." + [ds posts bundle-id] + (core/insert-selected-events! ds posts bundle-id))