Skip to content
Snippets Groups Projects
Commit a1848d0c authored by Bruno Burke's avatar Bruno Burke :hamburger:
Browse files

add keep-newest strategy for reset-cache.

parent 7e5cbf50
Branches master
No related tags found
No related merge requests found
Pipeline #180185 failed
......@@ -2,6 +2,14 @@
Hier werden alle Änderungen dokumentiert.
### 2024-02-14 - version 0.3.2
## Added
- add keep-newest strategy for reset-cache.
## Fixed
- document_stats now updates the column `updated_at` to represent the last access.
### 2023-01-27 - version 0.3.0
## Added
......
(defproject wwsoftware/document-storage "0.3.1"
(defproject wwsoftware/document-storage "0.3.2"
:description "FIXME: write description"
:repositories [["internal" {:url "https://maven.leukipp.de/releases"
:username "anonymous"}]]
......
......@@ -17,15 +17,46 @@ SELECT * FROM :i:cache-table WHERE "repository" = :repository-name
-- :result :raw
-- :doc reset the whole caching table
DELETE FROM :i:cache-table;
--;;
-- :name vacuum-document-cache!
-- :command :execute
-- :result :raw
-- :doc vacuum the whole caching table
VACUUM (VERBOSE) :i:cache-table;
--;;
-- :name reindex-document-cache!
-- :command :execute
-- :result :raw
-- :doc reindex the whole caching table
REINDEX TABLE :i:cache-table;
-- :name reset-document-cache-keep-newest!
-- :command :execute
-- :result :raw
-- :doc delete all cache records except the newest one for each document
DELETE FROM :i:cache-table
WHERE (repository, "document", "version") NOT IN (
SELECT repository, "document", MAX("version")
FROM :i:cache-table
GROUP BY repository, "document");
-- :name reset-document-cache-by-repository!
-- :command :execute
-- :result :raw
-- :doc delete only cache from a given repository
DELETE FROM :i:cache-table WHERE "repository" = :repository-name;
-- :name reset-document-cache-keep-newest-by-repository!
-- :command :execute
-- :result :raw
-- :doc delete only cache from a given repository, keeping the newest one for each document
DELETE FROM :i:cache-table
WHERE "repository" = :repository-name
AND (repository, "document", "version") NOT IN (
SELECT repository, "document", MAX("version")
FROM :i:cache-table
WHERE "repository" = :repository-name
GROUP BY repository, "document");
\ No newline at end of file
......@@ -4,7 +4,7 @@ INSERT INTO :i:document-stats-table AS st
(repository, "document", "version", request_count)
VALUES (:repository-name, :document-id, :version, 1)
ON CONFLICT(repository, "document", "version")
DO UPDATE SET request_count = st.request_count + 1
DO UPDATE SET request_count = st.request_count + 1, updated_at = CURRENT_TIMESTAMP
-- :name log-request! :! :n
-- :doc creates a new request-log record
......
......@@ -28,9 +28,10 @@
(.-storage-id this))
(get-cache [this]
(get (.-params this) :cache))
(create-repository [this {:keys [caching versioning delete-permanently] :or {caching false
versioning true
delete-permanently false}
(create-repository [this {:keys [caching versioning delete-permanently]
:or {caching false
versioning true
delete-permanently false}
:as repository}]
(.run-query this :create-repository!
{:repository (:name repository)
......@@ -83,10 +84,25 @@
:uuid (get-unique-id "ds")}]
(conman/query (:queries this) query-key
(merge table-names params))))
(reset-cache [this]
(.run-query this :reset-document-cache! {}))
(reset-repository-cache [this repository]
(.run-query this :reset-document-cache-by-repository! {:repository repository}))
(reset-cache [this {:keys [strategy]
:or {strategy :all}}]
(case strategy
:keep-newest
(.run-query this :reset-document-cache-keep-newest! {})
(.run-query this :reset-document-cache! {})))
(reset-repository-cache [this repository {:keys [strategy]
:or {strategy :all}}]
(case strategy
:keep-newest
(.run-query this :reset-document-cache-keep-newest-by-repository! {:repository repository})
(.run-query this :reset-document-cache-by-repository! {:repository repository})))
(maintain-cache [this]
(.run-query this :vacuum-document-cache! {})
(.run-query this :reindex-document-cache! {}))
(cached-repository? [this repository]
(let [repo-info (.run-query this :get-repository-info
{:repository repository})]
......
......@@ -8,8 +8,9 @@
(update-repository [this repository] "Update repository settings")
(delete-repository [this repository] "Delete a repository")
(delete-permanently? [this repository] "Check if repository enforces permanent deletion")
(reset-cache [this] "Clear and reset the document cache")
(reset-repository-cache [this repository] "Clear and reset the document cache for one repository")
(maintain-cache [this] "Maintain the document cache")
(reset-cache [this opts] "Clear and reset the document cache")
(reset-repository-cache [this repository opts] "Clear and reset the document cache for one repository")
(cached-repository? [this repository] "Checks if the repository will use caching")
(run-query [this query-key params] "Run a Query on a DB-based Storage"))
;;;TODO cached-document? method
......@@ -95,9 +95,12 @@
(merge table-names params
dstypes/frametype-map
dstypes/encoding-map))))
(reset-cache [this]
(maintain-cache [this]
;;TODO implement vacuum and reindex for sqlite.
)
(reset-cache [this {:keys [strategy] :or {strategy :keep-newest}}]
(.run-query this :reset-document-cache! {}))
(reset-repository-cache [this repository]
(reset-repository-cache [this repository {:keys [strategy] :or {strategy :keep-newest}}]
(.run-query this :reset-document-cache-by-repository! {:repository repository}))
(cached-repository? [this repository]
(let [repo-info (.run-query this :get-repository-info
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment