mirror of
https://github.com/penpot/penpot.git
synced 2025-05-13 03:16:36 +02:00
🔥 Remove unused code.
This commit is contained in:
parent
b441ffc20f
commit
422536d4a1
13 changed files with 61 additions and 51 deletions
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
;; --- Delete Projects
|
;; --- Delete Projects
|
||||||
|
|
||||||
(def ^:private clean-deleted-projects-sql
|
(def sql:remove-deleted-projects
|
||||||
"DELETE FROM projects
|
"DELETE FROM projects
|
||||||
WHERE deleted_at is not null
|
WHERE deleted_at is not null
|
||||||
AND (now()-deleted_at)::interval > '10 day'::interval
|
AND (now()-deleted_at)::interval > '10 day'::interval
|
||||||
|
@ -28,10 +28,11 @@
|
||||||
"Clean deleted projects."
|
"Clean deleted projects."
|
||||||
[opts]
|
[opts]
|
||||||
(db/with-atomic [conn db/pool]
|
(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)))))
|
(p/then (constantly nil)))))
|
||||||
|
|
||||||
(defstate projects-cleaner-task
|
(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
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
[uxbox.util.uuid :as uuid]
|
[uxbox.util.uuid :as uuid]
|
||||||
[vertx.core :as vc]))
|
[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)
|
"insert into users (id, fullname, username, email, password, photo, is_demo)
|
||||||
values ($1, $2, $3, $4, $5, '', true) returning *")
|
values ($1, $2, $3, $4, $5, '', true) returning *")
|
||||||
|
|
||||||
|
|
|
@ -102,7 +102,7 @@
|
||||||
(-> (ds/save storage filename path)
|
(-> (ds/save storage filename path)
|
||||||
(su/handle-on-context))))
|
(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)
|
"insert into images (user_id, name, collection_id, path, width, height, mimetype)
|
||||||
values ($1, $2, $3, $4, $5, $6, $7) returning *")
|
values ($1, $2, $3, $4, $5, $6, $7) returning *")
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@
|
||||||
|
|
||||||
;; --- Utilities
|
;; --- Utilities
|
||||||
|
|
||||||
(su/defstr sql:user-by-username-or-email
|
(def sql:user-by-username-or-email
|
||||||
"select u.*
|
"select u.*
|
||||||
from users as u
|
from users as u
|
||||||
where u.username=$1 or u.email=$1
|
where u.username=$1 or u.email=$1
|
||||||
|
@ -106,7 +106,7 @@
|
||||||
:code ::email-already-exists))
|
:code ::email-already-exists))
|
||||||
params)))
|
params)))
|
||||||
|
|
||||||
(su/defstr sql:update-profile
|
(def sql:update-profile
|
||||||
"update users
|
"update users
|
||||||
set username = $2,
|
set username = $2,
|
||||||
email = $3,
|
email = $3,
|
||||||
|
@ -213,7 +213,7 @@
|
||||||
|
|
||||||
;; --- Mutation: Register Profile
|
;; --- Mutation: Register Profile
|
||||||
|
|
||||||
(su/defstr sql:create-user
|
(def sql:create-user
|
||||||
"insert into users (id, fullname, username, email, password, photo)
|
"insert into users (id, fullname, username, email, password, photo)
|
||||||
values ($1, $2, $3, $4, $5, '') returning *")
|
values ($1, $2, $3, $4, $5, '') returning *")
|
||||||
|
|
||||||
|
@ -272,7 +272,7 @@
|
||||||
(s/def ::request-profile-recovery
|
(s/def ::request-profile-recovery
|
||||||
(s/keys :req-un [::username]))
|
(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)")
|
"insert into tokens (user_id, token) values ($1, $2)")
|
||||||
|
|
||||||
(sm/defmutation ::request-profile-recovery
|
(sm/defmutation ::request-profile-recovery
|
||||||
|
@ -301,7 +301,7 @@
|
||||||
(s/def ::recover-profile
|
(s/def ::recover-profile
|
||||||
(s/keys :req-un [::token ::password]))
|
(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")
|
"delete from tokenes where user_id=$1 and token=$2")
|
||||||
|
|
||||||
(sm/defmutation ::recover-profile
|
(sm/defmutation ::recover-profile
|
||||||
|
|
|
@ -115,7 +115,7 @@
|
||||||
(check-edition-permissions! conn user id)
|
(check-edition-permissions! conn user id)
|
||||||
(rename-file conn params)))
|
(rename-file conn params)))
|
||||||
|
|
||||||
(su/defstr sql:rename-file
|
(def sql:rename-file
|
||||||
"update project_files
|
"update project_files
|
||||||
set name = $2
|
set name = $2
|
||||||
where id = $1
|
where id = $1
|
||||||
|
|
|
@ -177,7 +177,7 @@
|
||||||
:changes changes})
|
:changes changes})
|
||||||
(retrieve-lagged-changes conn s params))))))))
|
(retrieve-lagged-changes conn s params))))))))
|
||||||
|
|
||||||
(su/defstr sql:lagged-snapshots
|
(def sql:lagged-snapshots
|
||||||
"select s.id, s.changes
|
"select s.id, s.changes
|
||||||
from project_page_snapshots as s
|
from project_page_snapshots as s
|
||||||
where s.page_id = $1
|
where s.page_id = $1
|
||||||
|
@ -209,7 +209,7 @@
|
||||||
(files/check-edition-permissions! conn user (:file-id page))
|
(files/check-edition-permissions! conn user (:file-id page))
|
||||||
(delete-page conn id))))
|
(delete-page conn id))))
|
||||||
|
|
||||||
(su/defstr sql:delete-page
|
(def sql:delete-page
|
||||||
"update project_pages
|
"update project_pages
|
||||||
set deleted_at = clock_timestamp()
|
set deleted_at = clock_timestamp()
|
||||||
where id = $1
|
where id = $1
|
||||||
|
|
|
@ -77,7 +77,7 @@
|
||||||
(check-edition-permissions! conn user id)
|
(check-edition-permissions! conn user id)
|
||||||
(rename-project conn params)))
|
(rename-project conn params)))
|
||||||
|
|
||||||
(su/defstr sql:rename-project
|
(def sql:rename-project
|
||||||
"update projects
|
"update projects
|
||||||
set name = $2
|
set name = $2
|
||||||
where id = $1
|
where id = $1
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
|
|
||||||
;; --- Query: Collections
|
;; --- Query: Collections
|
||||||
|
|
||||||
(def ^:private icons-collections-sql
|
(def sql:icons-collections
|
||||||
"select *,
|
"select *,
|
||||||
(select count(*) from icons where collection_id = ic.id) as num_icons
|
(select count(*) from icons where collection_id = ic.id) as num_icons
|
||||||
from icon_collections as ic
|
from icon_collections as ic
|
||||||
|
@ -42,7 +42,7 @@
|
||||||
|
|
||||||
(sq/defquery ::icons-collections
|
(sq/defquery ::icons-collections
|
||||||
[{:keys [user] :as params}]
|
[{:keys [user] :as params}]
|
||||||
(let [sqlv [icons-collections-sql user]]
|
(let [sqlv [sql:icons-collections user]]
|
||||||
(db/query db/pool sqlv)))
|
(db/query db/pool sqlv)))
|
||||||
|
|
||||||
;; --- Icons By Collection ID
|
;; --- Icons By Collection ID
|
||||||
|
|
|
@ -87,22 +87,22 @@
|
||||||
|
|
||||||
;; --- Query Images by Collection (id)
|
;; --- Query Images by Collection (id)
|
||||||
|
|
||||||
(su/defstr sql:images-by-collection
|
(def sql:images-by-collection
|
||||||
"select * from images
|
"select * from images
|
||||||
where (user_id = $1 or
|
where (user_id = $1 or
|
||||||
user_id = '00000000-0000-0000-0000-000000000000'::uuid)
|
user_id = '00000000-0000-0000-0000-000000000000'::uuid)
|
||||||
and deleted_at is null
|
and deleted_at is null
|
||||||
order by created_at desc")
|
order by created_at desc")
|
||||||
|
|
||||||
(su/defstr sql:images-by-collection1
|
(def sql:images-by-collection1
|
||||||
"with images as (~{sql:images-by-collection})
|
(str "with images as (" sql:images-by-collection ")
|
||||||
select im.* from images as im
|
select im.* from images as im
|
||||||
where im.collection_id is null")
|
where im.collection_id is null"))
|
||||||
|
|
||||||
(su/defstr sql:images-by-collection2
|
(def sql:images-by-collection2
|
||||||
"with images as (~{sql:images-by-collection})
|
(str "with images as (" sql:images-by-collection ")
|
||||||
select im.* from images as im
|
select im.* from images as im
|
||||||
where im.collection_id = $2")
|
where im.collection_id = $2"))
|
||||||
|
|
||||||
(s/def ::images-by-collection
|
(s/def ::images-by-collection
|
||||||
(s/keys :req-un [::user]
|
(s/keys :req-un [::user]
|
||||||
|
|
|
@ -2,12 +2,14 @@
|
||||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
;; 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/.
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
;;
|
;;
|
||||||
;; Copyright (c) 2019 Andrey Antukh <niwi@niwi.nz>
|
;; 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 <niwi@niwi.nz>
|
||||||
|
|
||||||
(ns uxbox.services.queries.project-files
|
(ns uxbox.services.queries.project-files
|
||||||
(:require
|
(:require
|
||||||
[clojure.spec.alpha :as s]
|
[clojure.spec.alpha :as s]
|
||||||
[cuerdas.core :as str]
|
|
||||||
[promesa.core :as p]
|
[promesa.core :as p]
|
||||||
[uxbox.common.spec :as us]
|
[uxbox.common.spec :as us]
|
||||||
[uxbox.db :as db]
|
[uxbox.db :as db]
|
||||||
|
@ -25,7 +27,7 @@
|
||||||
(s/def ::file-id ::us/uuid)
|
(s/def ::file-id ::us/uuid)
|
||||||
(s/def ::user ::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)
|
"select distinct on (pf.id, pf.created_at)
|
||||||
pf.*,
|
pf.*,
|
||||||
p.name as project_name,
|
p.name as project_name,
|
||||||
|
@ -58,16 +60,16 @@
|
||||||
(retrieve-recent-files db/pool params)
|
(retrieve-recent-files db/pool params)
|
||||||
(retrieve-project-files db/pool params)))
|
(retrieve-project-files db/pool params)))
|
||||||
|
|
||||||
(su/defstr sql:project-files
|
(def sql:project-files
|
||||||
"with files as (~{sql:generic-project-files})
|
(str "with files as (" sql:generic-project-files ")
|
||||||
select * from files where project_id = $2
|
select * from files where project_id = $2
|
||||||
order by created_at asc")
|
order by created_at asc"))
|
||||||
|
|
||||||
(su/defstr sql:recent-files
|
(def sql:recent-files
|
||||||
"with files as (~{sql:generic-project-files})
|
(str "with files as (" sql:generic-project-files ")
|
||||||
select * from files
|
select * from files
|
||||||
order by modified_at desc
|
order by modified_at desc
|
||||||
limit $2")
|
limit $2"))
|
||||||
|
|
||||||
(defn retrieve-project-files
|
(defn retrieve-project-files
|
||||||
[conn {:keys [user project-id]}]
|
[conn {:keys [user project-id]}]
|
||||||
|
@ -82,9 +84,9 @@
|
||||||
|
|
||||||
;; --- Query: Project File (By ID)
|
;; --- Query: Project File (By ID)
|
||||||
|
|
||||||
(su/defstr sql:project-file
|
(def sql:project-file
|
||||||
"with files as (~{sql:generic-project-files})
|
(str "with files as (" sql:generic-project-files ")
|
||||||
select * from files where id = $2")
|
select * from files where id = $2"))
|
||||||
|
|
||||||
(s/def ::project-file
|
(s/def ::project-file
|
||||||
(s/keys :req-un [::user ::id]))
|
(s/keys :req-un [::user ::id]))
|
||||||
|
@ -97,7 +99,18 @@
|
||||||
|
|
||||||
;; --- Query: Users of the File
|
;; --- 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
|
"select u.id, u.fullname, u.photo
|
||||||
from users as u
|
from users as u
|
||||||
join project_file_users as pfu on (pfu.user_id = u.id)
|
join project_file_users as pfu on (pfu.user_id = u.id)
|
||||||
|
@ -110,9 +123,9 @@
|
||||||
|
|
||||||
(declare retrieve-minimal-file)
|
(declare retrieve-minimal-file)
|
||||||
|
|
||||||
(su/defstr sql:minimal-file
|
(def sql:minimal-file
|
||||||
"with files as (~{sql:generic-project-files})
|
(str "with files as (" sql:generic-project-files ")
|
||||||
select id, project_id from files where id = $2")
|
select id, project_id from files where id = $2"))
|
||||||
|
|
||||||
(s/def ::project-file-users
|
(s/def ::project-file-users
|
||||||
(s/keys :req-un [::user ::file-id]))
|
(s/keys :req-un [::user ::file-id]))
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
(s/def ::project-id ::us/uuid)
|
(s/def ::project-id ::us/uuid)
|
||||||
(s/def ::file-id ::us/uuid)
|
(s/def ::file-id ::us/uuid)
|
||||||
|
|
||||||
(def ^:private sql:generic-project-pages
|
(def sql:generic-project-pages
|
||||||
"select pp.*
|
"select pp.*
|
||||||
from project_pages as pp
|
from project_pages as pp
|
||||||
inner join project_files as pf on (pf.id = pp.file_id)
|
inner join project_files as pf on (pf.id = pp.file_id)
|
||||||
|
@ -38,7 +38,7 @@
|
||||||
|
|
||||||
;; --- Query: Project Pages (By File ID)
|
;; --- Query: Project Pages (By File ID)
|
||||||
|
|
||||||
(def ^:private sql:project-pages
|
(def sql:project-pages
|
||||||
(str "with pages as (" sql:generic-project-pages ")"
|
(str "with pages as (" sql:generic-project-pages ")"
|
||||||
" select * from pages where file_id = $2"))
|
" select * from pages where file_id = $2"))
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
|
|
||||||
;; --- Query: Projects
|
;; --- Query: Projects
|
||||||
|
|
||||||
(su/defstr sql:projects
|
(def sql:projects
|
||||||
"select p.*
|
"select p.*
|
||||||
from project_users as pu
|
from project_users as pu
|
||||||
inner join projects as p on (p.id = pu.project_id)
|
inner join projects as p on (p.id = pu.project_id)
|
||||||
|
|
|
@ -25,10 +25,6 @@
|
||||||
;; (log/info "service" type "processed in" elapsed)
|
;; (log/info "service" type "processed in" elapsed)
|
||||||
;; data))})
|
;; data))})
|
||||||
|
|
||||||
(defmacro defstr
|
|
||||||
[sym str]
|
|
||||||
`(def ~sym (str/istr ~str)))
|
|
||||||
|
|
||||||
(defn raise-not-found-if-nil
|
(defn raise-not-found-if-nil
|
||||||
[v]
|
[v]
|
||||||
(if (nil? v)
|
(if (nil? v)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue