From 173f0d68bb286f01455f622f3df65717c62522b0 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 8 Aug 2022 09:42:45 +0200 Subject: [PATCH] :paperclip: Properly deprecate comments related queries --- backend/src/app/rpc/commands/comments.clj | 27 ++++++++----- backend/src/app/rpc/queries/comments.clj | 49 ++++++----------------- backend/src/app/rpc/queries/viewer.clj | 2 +- 3 files changed, 31 insertions(+), 47 deletions(-) diff --git a/backend/src/app/rpc/commands/comments.clj b/backend/src/app/rpc/commands/comments.clj index 0a3ef1941..0ccd222a8 100644 --- a/backend/src/app/rpc/commands/comments.clj +++ b/backend/src/app/rpc/commands/comments.clj @@ -130,9 +130,16 @@ (-> (db/exec-one! conn [sql profile-id file-id id]) (decode-row))))) -;; --- COMMAND: Comments +(defn get-comment-thread + [conn {:keys [profile-id file-id id share-id] :as params}] + (let [sql (str "with threads as (" sql:comment-threads ")" + "select * from threads where id = ?")] + (-> (db/exec-one! conn [sql profile-id file-id id]) + (decode-row)))) -(declare retrieve-comments) +;; --- COMMAND: Retrieve Comments + +(declare get-comments) (s/def ::file-id ::us/uuid) (s/def ::share-id (s/nilable ::us/uuid)) @@ -145,22 +152,24 @@ [{:keys [pool] :as cfg} {:keys [profile-id thread-id share-id] :as params}] (with-open [conn (db/open pool)] (let [thread (db/get-by-id conn :comment-thread thread-id)] - (files/check-comment-permissions! conn profile-id (:file-id thread) share-id) - (retrieve-comments conn thread-id)))) + (files/check-comment-permissions! conn profile-id (:file-id thread) share-id)) + (get-comments conn thread-id))) (def sql:comments "select c.* from comment as c where c.thread_id = ? order by c.created_at asc") -(defn retrieve-comments +(defn get-comments [conn thread-id] - (->> (db/exec! conn [sql:comments thread-id]) + (->> (db/query conn :comment + {:thread-id thread-id} + {:order-by [[:created-at :asc]]}) (into [] (map decode-row)))) ;; --- COMMAND: Get file comments users -(declare retrieve-file-comments-users) +(declare get-file-comments-users) (s/def ::file-id ::us/uuid) (s/def ::share-id (s/nilable ::us/uuid)) @@ -177,7 +186,7 @@ [{:keys [pool] :as cfg} {:keys [profile-id file-id share-id]}] (with-open [conn (db/open pool)] (files/check-comment-permissions! conn profile-id file-id share-id) - (retrieve-file-comments-users conn file-id profile-id))) + (get-file-comments-users conn file-id profile-id))) ;; All the profiles that had comment the file, plus the current ;; profile. @@ -197,6 +206,6 @@ FROM profile AS p WHERE p.id IN (SELECT id FROM available_profiles) OR p.id=?") -(defn retrieve-file-comments-users +(defn get-file-comments-users [conn file-id profile-id] (db/exec! conn [sql:file-comment-users file-id profile-id])) diff --git a/backend/src/app/rpc/queries/comments.clj b/backend/src/app/rpc/queries/comments.clj index aa57d9e8d..4a05a3924 100644 --- a/backend/src/app/rpc/queries/comments.clj +++ b/backend/src/app/rpc/queries/comments.clj @@ -23,27 +23,18 @@ ;; --- QUERY: Comment Threads -(s/def ::team-id ::us/uuid) -(s/def ::file-id ::us/uuid) -(s/def ::share-id (s/nilable ::us/uuid)) - -(s/def ::comment-threads - (s/and (s/keys :req-un [::profile-id] - :opt-un [::file-id ::share-id ::team-id]) - #(or (:file-id %) (:team-id %)))) +(s/def ::comment-threads ::cmd.comments/get-comment-threads) (sv/defmethod ::comment-threads - {::doc/deprecated "1.15"} + {::doc/added "1.0" + ::doc/deprecated "1.15"} [{:keys [pool] :as cfg} params] (with-open [conn (db/open pool)] (cmd.comments/retrieve-comment-threads conn params))) - ;; --- QUERY: Unread Comment Threads -(s/def ::team-id ::us/uuid) -(s/def ::unread-comment-threads - (s/keys :req-un [::profile-id ::team-id])) +(s/def ::unread-comment-threads ::cmd.comments/get-unread-comment-threads) (sv/defmethod ::unread-comment-threads {::doc/added "1.0" @@ -55,11 +46,7 @@ ;; --- QUERY: Single Comment Thread -(s/def ::id ::us/uuid) -(s/def ::share-id (s/nilable ::us/uuid)) -(s/def ::comment-thread - (s/keys :req-un [::profile-id ::file-id ::id] - :opt-un [::share-id])) +(s/def ::comment-thread ::cmd.comments/get-comment-thread) (sv/defmethod ::comment-thread {::doc/added "1.0" @@ -67,19 +54,11 @@ [{:keys [pool] :as cfg} {:keys [profile-id file-id id share-id] :as params}] (with-open [conn (db/open pool)] (files/check-comment-permissions! conn profile-id file-id share-id) - (let [sql (str "with threads as (" cmd.comments/sql:comment-threads ")" - "select * from threads where id = ?")] - (-> (db/exec-one! conn [sql profile-id file-id id]) - (decode-row))))) + (cmd.comments/get-comment-thread conn params))) ;; --- QUERY: Comments -(s/def ::file-id ::us/uuid) -(s/def ::share-id (s/nilable ::us/uuid)) -(s/def ::thread-id ::us/uuid) -(s/def ::comments - (s/keys :req-un [::profile-id ::thread-id] - :opt-un [::share-id])) +(s/def ::comments ::cmd.comments/get-comments) (sv/defmethod ::comments {::doc/added "1.0" @@ -87,17 +66,13 @@ [{:keys [pool] :as cfg} {:keys [profile-id thread-id share-id] :as params}] (with-open [conn (db/open pool)] (let [thread (db/get-by-id conn :comment-thread thread-id)] - (files/check-comment-permissions! conn profile-id (:file-id thread) share-id) - (cmd.comments/retrieve-comments conn thread-id)))) + (files/check-comment-permissions! conn profile-id (:file-id thread) share-id)) + (cmd.comments/get-comments conn thread-id))) + ;; --- QUERY: Get file comments users -(s/def ::file-id ::us/uuid) -(s/def ::share-id (s/nilable ::us/uuid)) - -(s/def ::file-comments-users - (s/keys :req-un [::profile-id ::file-id] - :opt-un [::share-id])) +(s/def ::file-comments-users ::cmd.comments/get-profiles-for-file-comments) (sv/defmethod ::file-comments-users {::doc/deprecated "1.15" @@ -105,4 +80,4 @@ [{:keys [pool] :as cfg} {:keys [profile-id file-id share-id]}] (with-open [conn (db/open pool)] (files/check-comment-permissions! conn profile-id file-id share-id) - (cmd.comments/retrieve-file-comments-users conn file-id profile-id))) + (cmd.comments/get-file-comments-users conn file-id profile-id))) diff --git a/backend/src/app/rpc/queries/viewer.clj b/backend/src/app/rpc/queries/viewer.clj index 681b8ef47..90234e4e2 100644 --- a/backend/src/app/rpc/queries/viewer.clj +++ b/backend/src/app/rpc/queries/viewer.clj @@ -27,7 +27,7 @@ (p/let [file (files/retrieve-file cfg file-id) project (retrieve-project pool (:project-id file)) libs (files/retrieve-file-libraries cfg false file-id) - users (comments/retrieve-file-comments-users pool file-id profile-id) + users (comments/get-file-comments-users pool file-id profile-id) links (->> (db/query pool :share-link {:file-id file-id}) (mapv slnk/decode-share-link-row))