0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-11 07:11:32 -05:00

🔥 Remove unused code.

This commit is contained in:
Andrey Antukh 2020-01-14 15:29:36 +01:00
parent b441ffc20f
commit 422536d4a1
13 changed files with 61 additions and 51 deletions

View file

@ -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

View file

@ -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 *")

View file

@ -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 *")

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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]

View file

@ -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 <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
(: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]))

View file

@ -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"))

View file

@ -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)

View file

@ -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)