From 422536d4a1c816f5c599838c715cb0f31f3518cd Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 14 Jan 2020 15:29:36 +0100 Subject: [PATCH] :fire: Remove unused code. --- backend/src/uxbox/jobs/gc.clj | 7 +-- backend/src/uxbox/services/mutations/demo.clj | 2 +- .../src/uxbox/services/mutations/images.clj | 2 +- .../src/uxbox/services/mutations/profile.clj | 10 ++-- .../services/mutations/project_files.clj | 2 +- .../services/mutations/project_pages.clj | 4 +- .../src/uxbox/services/mutations/projects.clj | 2 +- backend/src/uxbox/services/queries/icons.clj | 4 +- backend/src/uxbox/services/queries/images.clj | 18 +++---- .../uxbox/services/queries/project_files.clj | 51 ++++++++++++------- .../uxbox/services/queries/project_pages.clj | 4 +- .../src/uxbox/services/queries/projects.clj | 2 +- backend/src/uxbox/services/util.clj | 4 -- 13 files changed, 61 insertions(+), 51 deletions(-) diff --git a/backend/src/uxbox/jobs/gc.clj b/backend/src/uxbox/jobs/gc.clj index d56470e14..04ae9f6ef 100644 --- a/backend/src/uxbox/jobs/gc.clj +++ b/backend/src/uxbox/jobs/gc.clj @@ -18,7 +18,7 @@ ;; --- Delete Projects -(def ^:private clean-deleted-projects-sql +(def sql:remove-deleted-projects "DELETE FROM projects WHERE deleted_at is not null AND (now()-deleted_at)::interval > '10 day'::interval @@ -28,10 +28,11 @@ "Clean deleted projects." [opts] (db/with-atomic [conn db/pool] - (-> (db/query-one conn clean-deleted-projects-sql) + (-> (db/query-one conn sql:remove-deleted-projects) (p/then (constantly nil))))) (defstate projects-cleaner-task - :start (uj/schedule! system #'clean-deleted-projects {::uj/interval 3600000})) ;; 1h + :start (uj/schedule! system #'clean-deleted-projects + {::uj/interval 3600000})) ;; 1h diff --git a/backend/src/uxbox/services/mutations/demo.clj b/backend/src/uxbox/services/mutations/demo.clj index 79e54db04..20063955d 100644 --- a/backend/src/uxbox/services/mutations/demo.clj +++ b/backend/src/uxbox/services/mutations/demo.clj @@ -32,7 +32,7 @@ [uxbox.util.uuid :as uuid] [vertx.core :as vc])) -(su/defstr sql:create-demo-user +(def sql:create-demo-user "insert into users (id, fullname, username, email, password, photo, is_demo) values ($1, $2, $3, $4, $5, '', true) returning *") diff --git a/backend/src/uxbox/services/mutations/images.clj b/backend/src/uxbox/services/mutations/images.clj index 39c144a84..b6e0e9af4 100644 --- a/backend/src/uxbox/services/mutations/images.clj +++ b/backend/src/uxbox/services/mutations/images.clj @@ -102,7 +102,7 @@ (-> (ds/save storage filename path) (su/handle-on-context)))) -(su/defstr sql:create-image +(def sql:create-image "insert into images (user_id, name, collection_id, path, width, height, mimetype) values ($1, $2, $3, $4, $5, $6, $7) returning *") diff --git a/backend/src/uxbox/services/mutations/profile.clj b/backend/src/uxbox/services/mutations/profile.clj index 55517ba1e..35fa6859d 100644 --- a/backend/src/uxbox/services/mutations/profile.clj +++ b/backend/src/uxbox/services/mutations/profile.clj @@ -44,7 +44,7 @@ ;; --- Utilities -(su/defstr sql:user-by-username-or-email +(def sql:user-by-username-or-email "select u.* from users as u where u.username=$1 or u.email=$1 @@ -106,7 +106,7 @@ :code ::email-already-exists)) params))) -(su/defstr sql:update-profile +(def sql:update-profile "update users set username = $2, email = $3, @@ -213,7 +213,7 @@ ;; --- Mutation: Register Profile -(su/defstr sql:create-user +(def sql:create-user "insert into users (id, fullname, username, email, password, photo) values ($1, $2, $3, $4, $5, '') returning *") @@ -272,7 +272,7 @@ (s/def ::request-profile-recovery (s/keys :req-un [::username])) -(su/defstr sql:insert-recovery-token +(def sql:insert-recovery-token "insert into tokens (user_id, token) values ($1, $2)") (sm/defmutation ::request-profile-recovery @@ -301,7 +301,7 @@ (s/def ::recover-profile (s/keys :req-un [::token ::password])) -(su/defstr sql:remove-recovery-token +(def sql:remove-recovery-token "delete from tokenes where user_id=$1 and token=$2") (sm/defmutation ::recover-profile diff --git a/backend/src/uxbox/services/mutations/project_files.clj b/backend/src/uxbox/services/mutations/project_files.clj index 8467b4ed2..ad153356b 100644 --- a/backend/src/uxbox/services/mutations/project_files.clj +++ b/backend/src/uxbox/services/mutations/project_files.clj @@ -115,7 +115,7 @@ (check-edition-permissions! conn user id) (rename-file conn params))) -(su/defstr sql:rename-file +(def sql:rename-file "update project_files set name = $2 where id = $1 diff --git a/backend/src/uxbox/services/mutations/project_pages.clj b/backend/src/uxbox/services/mutations/project_pages.clj index 52948a679..06a67f0e4 100644 --- a/backend/src/uxbox/services/mutations/project_pages.clj +++ b/backend/src/uxbox/services/mutations/project_pages.clj @@ -177,7 +177,7 @@ :changes changes}) (retrieve-lagged-changes conn s params)))))))) -(su/defstr sql:lagged-snapshots +(def sql:lagged-snapshots "select s.id, s.changes from project_page_snapshots as s where s.page_id = $1 @@ -209,7 +209,7 @@ (files/check-edition-permissions! conn user (:file-id page)) (delete-page conn id)))) -(su/defstr sql:delete-page +(def sql:delete-page "update project_pages set deleted_at = clock_timestamp() where id = $1 diff --git a/backend/src/uxbox/services/mutations/projects.clj b/backend/src/uxbox/services/mutations/projects.clj index c2ffd7742..aedbb6df7 100644 --- a/backend/src/uxbox/services/mutations/projects.clj +++ b/backend/src/uxbox/services/mutations/projects.clj @@ -77,7 +77,7 @@ (check-edition-permissions! conn user id) (rename-project conn params))) -(su/defstr sql:rename-project +(def sql:rename-project "update projects set name = $2 where id = $1 diff --git a/backend/src/uxbox/services/queries/icons.clj b/backend/src/uxbox/services/queries/icons.clj index 36fdffa89..e9b23f56f 100644 --- a/backend/src/uxbox/services/queries/icons.clj +++ b/backend/src/uxbox/services/queries/icons.clj @@ -28,7 +28,7 @@ ;; --- Query: Collections -(def ^:private icons-collections-sql +(def sql:icons-collections "select *, (select count(*) from icons where collection_id = ic.id) as num_icons from icon_collections as ic @@ -42,7 +42,7 @@ (sq/defquery ::icons-collections [{:keys [user] :as params}] - (let [sqlv [icons-collections-sql user]] + (let [sqlv [sql:icons-collections user]] (db/query db/pool sqlv))) ;; --- Icons By Collection ID diff --git a/backend/src/uxbox/services/queries/images.clj b/backend/src/uxbox/services/queries/images.clj index 033b37574..ad1b04a5b 100644 --- a/backend/src/uxbox/services/queries/images.clj +++ b/backend/src/uxbox/services/queries/images.clj @@ -87,22 +87,22 @@ ;; --- Query Images by Collection (id) -(su/defstr sql:images-by-collection +(def sql:images-by-collection "select * from images where (user_id = $1 or user_id = '00000000-0000-0000-0000-000000000000'::uuid) and deleted_at is null order by created_at desc") -(su/defstr sql:images-by-collection1 - "with images as (~{sql:images-by-collection}) - select im.* from images as im - where im.collection_id is null") +(def sql:images-by-collection1 + (str "with images as (" sql:images-by-collection ") + select im.* from images as im + where im.collection_id is null")) -(su/defstr sql:images-by-collection2 - "with images as (~{sql:images-by-collection}) - select im.* from images as im - where im.collection_id = $2") +(def sql:images-by-collection2 + (str "with images as (" sql:images-by-collection ") + select im.* from images as im + where im.collection_id = $2")) (s/def ::images-by-collection (s/keys :req-un [::user] diff --git a/backend/src/uxbox/services/queries/project_files.clj b/backend/src/uxbox/services/queries/project_files.clj index 92df618e7..24ef0fd3d 100644 --- a/backend/src/uxbox/services/queries/project_files.clj +++ b/backend/src/uxbox/services/queries/project_files.clj @@ -2,12 +2,14 @@ ;; License, v. 2.0. If a copy of the MPL was not distributed with this ;; file, You can obtain one at http://mozilla.org/MPL/2.0/. ;; -;; Copyright (c) 2019 Andrey Antukh +;; This Source Code Form is "Incompatible With Secondary Licenses", as +;; defined by the Mozilla Public License, v. 2.0. +;; +;; Copyright (c) 2019-2020 Andrey Antukh (ns uxbox.services.queries.project-files (:require [clojure.spec.alpha :as s] - [cuerdas.core :as str] [promesa.core :as p] [uxbox.common.spec :as us] [uxbox.db :as db] @@ -25,7 +27,7 @@ (s/def ::file-id ::us/uuid) (s/def ::user ::us/uuid) -(su/defstr sql:generic-project-files +(def sql:generic-project-files "select distinct on (pf.id, pf.created_at) pf.*, p.name as project_name, @@ -58,16 +60,16 @@ (retrieve-recent-files db/pool params) (retrieve-project-files db/pool params))) -(su/defstr sql:project-files - "with files as (~{sql:generic-project-files}) - select * from files where project_id = $2 - order by created_at asc") +(def sql:project-files + (str "with files as (" sql:generic-project-files ") + select * from files where project_id = $2 + order by created_at asc")) -(su/defstr sql:recent-files - "with files as (~{sql:generic-project-files}) - select * from files - order by modified_at desc - limit $2") +(def sql:recent-files + (str "with files as (" sql:generic-project-files ") + select * from files + order by modified_at desc + limit $2")) (defn retrieve-project-files [conn {:keys [user project-id]}] @@ -82,9 +84,9 @@ ;; --- Query: Project File (By ID) -(su/defstr sql:project-file - "with files as (~{sql:generic-project-files}) - select * from files where id = $2") +(def sql:project-file + (str "with files as (" sql:generic-project-files ") + select * from files where id = $2")) (s/def ::project-file (s/keys :req-un [::user ::id])) @@ -97,7 +99,18 @@ ;; --- Query: Users of the File -(su/defstr sql:file-users +(def sql:file-users + "select u.id, u.fullname, u.photo + from users as u + join project_file_users as pfu on (pfu.user_id = u.id) + where pfu.file_id = $1 + union all + select u.id, u.fullname, u.photo + from users as u + join project_users as pu on (pu.user_id = u.id) + where pu.project_id = $2") + +(def sql:file-users "select u.id, u.fullname, u.photo from users as u join project_file_users as pfu on (pfu.user_id = u.id) @@ -110,9 +123,9 @@ (declare retrieve-minimal-file) -(su/defstr sql:minimal-file - "with files as (~{sql:generic-project-files}) - select id, project_id from files where id = $2") +(def sql:minimal-file + (str "with files as (" sql:generic-project-files ") + select id, project_id from files where id = $2")) (s/def ::project-file-users (s/keys :req-un [::user ::file-id])) diff --git a/backend/src/uxbox/services/queries/project_pages.clj b/backend/src/uxbox/services/queries/project_pages.clj index c2e884609..cffdaaa4a 100644 --- a/backend/src/uxbox/services/queries/project_pages.clj +++ b/backend/src/uxbox/services/queries/project_pages.clj @@ -24,7 +24,7 @@ (s/def ::project-id ::us/uuid) (s/def ::file-id ::us/uuid) -(def ^:private sql:generic-project-pages +(def sql:generic-project-pages "select pp.* from project_pages as pp inner join project_files as pf on (pf.id = pp.file_id) @@ -38,7 +38,7 @@ ;; --- Query: Project Pages (By File ID) -(def ^:private sql:project-pages +(def sql:project-pages (str "with pages as (" sql:generic-project-pages ")" " select * from pages where file_id = $2")) diff --git a/backend/src/uxbox/services/queries/projects.clj b/backend/src/uxbox/services/queries/projects.clj index b428f67be..9bdf66364 100644 --- a/backend/src/uxbox/services/queries/projects.clj +++ b/backend/src/uxbox/services/queries/projects.clj @@ -26,7 +26,7 @@ ;; --- Query: Projects -(su/defstr sql:projects +(def sql:projects "select p.* from project_users as pu inner join projects as p on (p.id = pu.project_id) diff --git a/backend/src/uxbox/services/util.clj b/backend/src/uxbox/services/util.clj index 3b0705ca1..bf7e23bd1 100644 --- a/backend/src/uxbox/services/util.clj +++ b/backend/src/uxbox/services/util.clj @@ -25,10 +25,6 @@ ;; (log/info "service" type "processed in" elapsed) ;; data))}) -(defmacro defstr - [sym str] - `(def ~sym (str/istr ~str))) - (defn raise-not-found-if-nil [v] (if (nil? v)