Line data Source code
1 4 : (ns matchscore.domain.user.query
2 : (:require
3 : [matchscore.domain.user.repository.postgres :as user-postgres-repo]
4 : [matchscore.domain.user.repository.redis :as redis-repo]
5 : [taoensso.telemere :as t]))
6 :
7 :
8 4 : (defn get-user
9 : "Retrieves a user by ID. Returns User map or nil."
10 : [repo id]
11 12 : (user-postgres-repo/find-by-id repo id))
12 :
13 :
14 4 : (defn get-users-by-ids
15 : "Retrieves participants by multiple IDs. Returns seq."
16 : [repo ids]
17 12 : (user-postgres-repo/find-by-ids repo ids))
18 :
19 :
20 4 : (defn get-users
21 : "Retrieves all users. Tries Redis cache first, falls back to Postgres."
22 : [repo redis]
23 26 : (if-some [cached (when redis (redis-repo/get-all-cached redis))]
24 1 : cached
25 8 : (let [users (user-postgres-repo/get-all repo)]
26 18 : (when (and redis (seq users))
27 8 : (redis-repo/cache-all! redis users)
28 44 : (t/log! :debug "Cached users to Redis"))
29 2 : users)))
30 :
31 :
32 4 : (defn search-users
33 : "Search users by filters and pagination. Returns paginated result."
34 : [repo filters pagination]
35 5 : (user-postgres-repo/search repo filters pagination))
36 :
37 :
38 4 : (defn search-users-for-event
39 : "Search users excluding those already participating in the given event."
40 : [repo event-id filters pagination]
41 6 : (user-postgres-repo/search-excluding-event repo event-id filters pagination))
42 :
43 :
44 4 : (defn search-users-for-template
45 : "Search users excluding those already participating in the given template."
46 : [repo template-id filters pagination]
47 6 : (user-postgres-repo/search-excluding-template repo template-id filters pagination))
48 :
49 :
50 4 : (defn find-uuid-by-telegram-id
51 : "Finds user UUID by telegram-id. Tries Redis cache first, falls back to Postgres."
52 : [repo redis telegram-id]
53 39 : (or
54 28 : (when redis (redis-repo/get-uuid-by-telegram-id redis telegram-id))
55 16 : (when-let [user (user-postgres-repo/find-by-telegram-id repo telegram-id)]
56 40 : (when redis (redis-repo/cache-uuid-by-telegram-id! redis telegram-id (:uuid user)))
57 12 : (:uuid user))))
|