|
54 | 54 | (fn [{:keys [args ds]}] |
55 | 55 | (let [{:keys [bundle-id categories]} args |
56 | 56 | ds-bundle (db.util/conn :bundle bundle-id) |
57 | | - incoming-posts (services/incoming-posts-with-feeds (db.util/conn) {:where [:= :feeds.state "live"]}) |
| 57 | + incoming-posts (services/incoming-posts-with-feeds ds {:where [:= :feeds.state "live"]}) |
58 | 58 | posts-categories (incoming-posts/categories-by-posts ds {:where [:= :state "live"]})] |
59 | 59 | (run! |
60 | 60 | (fn [post] |
61 | 61 | ; calculate score for post |
62 | 62 | ; determine number of categories matched |
63 | | - (let [; get vector of category ids in the given post, e.g. [1 3] |
64 | | - post-categories-vec (reduce (fn [acc {:keys [post-id id]}] |
65 | | - (if (= post-id (:id post)) |
66 | | - (conj acc id) |
67 | | - acc)) [] posts-categories) |
| 63 | + ; get vector of category ids in the given post, e.g. [1 3] |
| 64 | + (let [post-categories-vec (->> posts-categories |
| 65 | + (mapv (fn [{:keys [post-id id]}] |
| 66 | + (when (= post-id (:id post)) id))) |
| 67 | + (filterv identity)) |
68 | 68 | ; get vector of category ids in categories to match, e.g. [1 2 3 4] |
69 | 69 | match-categories-vec (reduce (fn [acc {:keys [id]}] |
70 | 70 | (conj acc id)) [] categories) |
|
77 | 77 | incoming-posts) |
78 | 78 |
|
79 | 79 | ; pull highest scored posts by long heuristics into outgoing posts |
80 | | - (let [; top 30 post-heuristics records ordered by long heuristic in descending order |
81 | | - top-by-long-heuristics (services/top-posts-by-heuristic ds-bundle |
| 80 | + ; top 100 post-heuristics records ordered by long heuristic in descending order |
| 81 | + (let [top-by-long-heuristics (services/top-posts-by-heuristic ds-bundle |
82 | 82 | {:heuristic :long-heuristic |
83 | | - :limit 30}) |
| 83 | + :limit 100}) |
84 | 84 | ; convert into a vector of id numbers |
85 | | - ids (reduce (fn [acc {:keys [id]}] |
86 | | - (conj acc id)) [] top-by-long-heuristics) |
| 85 | + ids (mapv :post-id top-by-long-heuristics) |
87 | 86 |
|
88 | 87 | ; get all incoming posts with the above id numbers |
89 | 88 | posts-in (services/incoming-posts ds {:where [:in :id ids]}) |
|
95 | 94 | [] posts-in)] |
96 | 95 | (when (seq posts-in) |
97 | 96 | (services/upsert-outgoing-posts! ds-bundle {:data outgoing-posts})))))) |
98 | | - |
0 commit comments