|
293 | 293 | sql/format) |
294 | 294 | (execute! db) |
295 | 295 | adapters/db->social-definition)) |
| 296 | + |
| 297 | +(defn get-top-authors |
| 298 | + {:malli/schema [:=> [:cat :int schemas.types/DatabaseComponent] |
| 299 | + [:maybe [:sequential schemas.model.social/Author+Interactions]]]} |
| 300 | + [limit db] |
| 301 | + (->> (-> (sql.helpers/select |
| 302 | + :author/* |
| 303 | + [[:count :social/id] :interactions]) |
| 304 | + (sql.helpers/from [(sql.helpers/union-all |
| 305 | + (-> (sql.helpers/select |
| 306 | + [:note/note-id :id] |
| 307 | + [:note/author-id :author-id]) |
| 308 | + (sql.helpers/from :note)) |
| 309 | + (-> (sql.helpers/select |
| 310 | + [:example-edit/example-edit-id :id] |
| 311 | + [:example-edit/author-id :author-id]) |
| 312 | + (sql.helpers/from :example-edit)) |
| 313 | + (-> (sql.helpers/select |
| 314 | + [:see-also/see-also-id :id] |
| 315 | + [:see-also/author-id :author-id]) |
| 316 | + (sql.helpers/from :see-also))) :social]) |
| 317 | + (sql.helpers/join :author |
| 318 | + [:= :social/author-id :author/author-id]) |
| 319 | + (sql.helpers/group-by :author/author-id) |
| 320 | + (sql.helpers/order-by [:interactions :desc]) |
| 321 | + (sql.helpers/limit limit) |
| 322 | + sql/format) |
| 323 | + (execute! db) |
| 324 | + adapters/db->author+interaction)) |
| 325 | + |
| 326 | +(defn get-latest-interactions |
| 327 | + {:malli/schema [:=> [:cat :int schemas.types/DatabaseComponent] |
| 328 | + [:maybe [:sequential schemas.model.social/AnySocial]]]} |
| 329 | + [limit db] |
| 330 | + (->> (-> (sql.helpers/union-all |
| 331 | + get-note-query |
| 332 | + get-example-query |
| 333 | + get-see-also-query) |
| 334 | + (sql.helpers/order-by [:created :desc]) |
| 335 | + (sql.helpers/limit limit) |
| 336 | + sql/format) |
| 337 | + (execute! db) |
| 338 | + adapters/db->any-socials)) |
0 commit comments