Don't import already imported material.

This commit is contained in:
Andrey Antukh 2016-11-21 18:55:44 +01:00
parent 4aa888f72d
commit c018a39f7b
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95

View file

@ -31,7 +31,7 @@
;; --- Constants & Helpers ;; --- Constants & Helpers
(def ^:const +imates-uuid-ns+ #uuid "3642a582-565f-4070-beba-af797ab27a6e") (def ^:const +images-uuid-ns+ #uuid "3642a582-565f-4070-beba-af797ab27a6e")
(def ^:const +icons-uuid-ns+ #uuid "3642a582-565f-4070-beba-af797ab27a6f") (def ^:const +icons-uuid-ns+ #uuid "3642a582-565f-4070-beba-af797ab27a6f")
(s/def ::name string?) (s/def ::name string?)
@ -50,7 +50,7 @@
(defn- create-icons-collection (defn- create-icons-collection
"Create or replace image collection by its name." "Create or replace image collection by its name."
[conn {:keys [name] :as entry}] [conn {:keys [name] :as entry}]
(println "Creating icons collection:" name) (println "Creating or updating icons collection:" name)
(let [id (uuid/namespaced +icons-uuid-ns+ name) (let [id (uuid/namespaced +icons-uuid-ns+ name)
sqlv (sql/create-icons-collection {:id id :name name})] sqlv (sql/create-icons-collection {:id id :name name})]
(sc/execute conn sqlv) (sc/execute conn sqlv)
@ -85,10 +85,11 @@
(defn- import-icon (defn- import-icon
[conn id fpath] [conn id fpath]
{:pre [(uuid? id) (fs/path? fpath)]} {:pre [(uuid? id) (fs/path? fpath)]}
(println "Importing icon:" (str fpath))
(let [filename (fs/base-name fpath) (let [filename (fs/base-name fpath)
iconid (uuid/namespaced +imates-uuid-ns+ (str id filename))] iconid (uuid/namespaced +icons-uuid-ns+ (str id filename))]
(create-icon conn id iconid fpath))) (when-not (retrieve-icon conn iconid)
(println "Importing icon:" (str fpath))
(create-icon conn id iconid fpath))))
(defn- process-icons-entry (defn- process-icons-entry
[conn basedir {:keys [path regex] :as entry}] [conn basedir {:keys [path regex] :as entry}]
@ -104,8 +105,8 @@
(defn- create-images-collection (defn- create-images-collection
"Create or replace image collection by its name." "Create or replace image collection by its name."
[conn {:keys [name] :as entry}] [conn {:keys [name] :as entry}]
(println "Creating image collection:" name) (println "Creating or updating image collection:" name)
(let [id (uuid/namespaced +imates-uuid-ns+ name) (let [id (uuid/namespaced +images-uuid-ns+ name)
sqlv (sql/create-images-collection {:id id :name name})] sqlv (sql/create-images-collection {:id id :name name})]
(sc/execute conn sqlv) (sc/execute conn sqlv)
id)) id))
@ -138,7 +139,7 @@
(uuid? imageid)]} (uuid? imageid)]}
(let [filename (fs/base-name localpath) (let [filename (fs/base-name localpath)
storage media/images-storage storage media/images-storage
[width height] (time (retrieve-image-size localpath)) [width height] (retrieve-image-size localpath)
extension (second (fs/split-ext filename)) extension (second (fs/split-ext filename))
path @(st/save storage filename localpath) path @(st/save storage filename localpath)
params {:name filename params {:name filename
@ -156,14 +157,17 @@
(defn- import-image (defn- import-image
[conn id fpath] [conn id fpath]
{:pre [(uuid? id) (fs/path? fpath)]} {:pre [(uuid? id) (fs/path? fpath)]}
(println "Importing image:" (str fpath))
(let [filename (fs/base-name fpath) (let [filename (fs/base-name fpath)
imageid (uuid/namespaced +imates-uuid-ns+ (str id filename))] imageid (uuid/namespaced +images-uuid-ns+ (str id filename))]
(if-let [image (retrieve-image conn imageid)] (when-not (retrieve-image conn imageid)
(println "Importing image:" (str fpath))
(create-image conn id imageid fpath))))
#_(if-let [image (retrieve-image conn imageid)]
(do (do
(delete-image conn image) (delete-image conn image)
(create-image conn id imageid fpath)) (create-image conn id imageid fpath))
(create-image conn id imageid fpath)))) (create-image conn id imageid fpath))
(defn- process-images-entry (defn- process-images-entry
[conn basedir {:keys [path regex] :as entry}] [conn basedir {:keys [path regex] :as entry}]