File tree Expand file tree Collapse file tree 1 file changed +9
-7
lines changed
Clojure-Websockets/src/clj/birdwatch Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change 55
55
(def chsk-send! send-fn ) ; ChannelSocket's send API fn
56
56
(def connected-uids connected-uids )) ; Watchable, read-only atom
57
57
58
+ (def subscriptions (atom {}))
58
59
59
60
(defn start-percolator [params]
61
+ " register percolation search with ID based on hash of the query"
60
62
(let [q (:query params)
61
- sha (sha1 (str q))]
62
- (perc/register-query conn " percolator" sha :query q) ; register percolation search with ID based on hash of the query
63
+ sha (sha1 (str q))
64
+ uid (:uid params)]
65
+ (swap! subscriptions assoc uid sha)
66
+ (perc/register-query conn " percolator" sha :query q)
63
67
(log/info " Percolation registered for query" q " with SHA1" sha)))
64
68
65
69
(defn query [params]
183
187
(let [t (<! tweets-chan)]
184
188
(let [response (perc/percolate conn " percolator" " tweet" :doc t)
185
189
matches (into #{} (map #(:_id %1 ) (esrsp/matches-from response)))]
186
- (log/info " esrsp/matches-from" matches))
187
-
188
- (doseq [uid (:any @connected-uids)]
189
- (chsk-send! uid [:tweet/new t]))
190
-
190
+ (doseq [uid (:any @connected-uids)]
191
+ (when (contains? matches (get @subscriptions uid))
192
+ (chsk-send! uid [:tweet/new t]))))
191
193
(try
192
194
(esd/put conn (:es-index twitter-conf) " tweet" (:id_str t) t)
193
195
(catch Exception ex (log/error ex " esd/put error" ))))))
You can’t perform that action at this time.
0 commit comments