3131 :lock (ReentrantLock. )}
3232 migrate))
3333
34- #_(mount/start #'db)
34+ #_(do ( mount/stop #'db) ( mount/ start #'db) )
3535
3636; ;;; DB interaction
3737
5151(defn insert-profile [profile]
5252 (m/assert Profile profile)
5353 (let [{:keys [id file_path profile_type sample_count owner upload_ts
54- edit_token is_public]} profile]
54+ edit_token config is_public]} profile]
5555 (log/infof " Inserting profile %s from %s" id owner)
5656 (with-locking (:lock @db)
5757 (jdbc/with-transaction [tx @db]
6363 :sample_count sample_count
6464 :is_public is_public
6565 :edit_token edit_token
66+ :config config
6667 :owner owner})
6768 (jdbc/execute-one! tx [" UPDATE stats SET val = val + 1 WHERE stat = 'total_uploaded'" ])))
6869 profile))
7374
7475(defn list-profiles []
7576 (with-locking (:lock @db)
76- (->> (jdbc/execute! @db [" SELECT id, file_path, profile_type, sample_count, owner, upload_ts, is_public FROM profile" ])
77+ (->> (jdbc/execute! @db [" SELECT id, file_path, profile_type, sample_count, owner, config, upload_ts, is_public FROM profile" ])
7778 (mapv #(-> (unqualify-keys %)
7879 (assoc :edit_token nil )
7980 (coerce Profile))))))
8081
8182(defn list-public-profiles [n]
8283 (with-locking (:lock @db)
83- (->> (jdbc/execute! @db [" SELECT id, file_path, profile_type, sample_count, owner, upload_ts, is_public, edit_token FROM profile
84+ (->> (jdbc/execute! @db [" SELECT id, file_path, profile_type, sample_count, owner, config, upload_ts, is_public, edit_token FROM profile
8485WHERE is_public = 1 ORDER BY upload_ts DESC LIMIT ?" n])
8586 (mapv #(-> (unqualify-keys %)
8687 (coerce Profile))))))
8788
8889(defn get-profile [profile-id]
8990 (with-locking (:lock @db)
90- (let [q [" SELECT id, file_path, profile_type, sample_count, owner, upload_ts, edit_token, is_public FROM profile WHERE id = ?" profile-id]
91+ (let [q [" SELECT id, file_path, profile_type, sample_count, owner, config, upload_ts, edit_token, is_public FROM profile WHERE id = ?" profile-id]
9192 row (some-> (jdbc/execute-one! @db q)
9293 unqualify-keys
9394 (coerce Profile))]
@@ -103,6 +104,10 @@ WHERE is_public = 1 ORDER BY upload_ts DESC LIMIT ?" n])
103104 (when (zero? update-count)
104105 (raise 404 (format " Profile with ID '%s' not found." profile-id))))))
105106
107+ (defn save-profile-config [profile-id config]
108+ (with-locking (:lock @db)
109+ (sql-helpers/update! @db :profile {:config config} {:id profile-id})))
110+
106111(defn clear-db []
107112 (with-locking (:lock @db)
108113 (.delete (clojure.java.io/file (@config :db :path )))
0 commit comments