Created
March 29, 2012 17:21
-
-
Save drsnyder/2240252 to your computer and use it in GitHub Desktop.
Getting display order
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn display-order-page-sql [ids scores] | |
(sql/with-conn | |
(sql/query (format "WITH display_order AS ( | |
SELECT UNNEST(ARRAY[%s]) AS id, | |
UNNEST(ARRAY[%s]) AS pos | |
) | |
SELECT * FROM display_order | |
JOIN forum_posts ON ( | |
display_order.id = forum_posts.id | |
) | |
ORDER BY display_order.pos DESC", | |
(clojure.string/join "," ids), | |
(clojure.string/join "," scores))))) | |
(defn display-order-page [domain thread_id offset limit] | |
(let [c (new-container (container-key domain thread_id)) | |
objects (with c (fn [c] (page c offset limit))) | |
ids (map #(ident %) objects) | |
scores (map #(score %) objects)] | |
(display-order-page-sql ids scores))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment