diff options
| author | eltrac <hi@eltr.ac> | 2026-10-24 16:49:48 +0800 |
|---|---|---|
| committer | eltrac <hi@eltr.ac> | 2026-10-24 16:50:00 +0800 |
| commit | fbbea552acc89938b9086829a8b86c4b92a784fd (patch) | |
| tree | 7f9a4bba12892b132ed984d012a9242f36658411 /src | |
| parent | bc0919fd2fce876172c644fdb0cdba98495e4142 (diff) | |
storage: query result is always in chronological order #79
Diffstat (limited to 'src')
| -rw-r--r-- | src/weepinbell/storage/edn_storage.clj | 2 | ||||
| -rw-r--r-- | src/weepinbell/storage/h2.clj | 13 |
2 files changed, 10 insertions, 5 deletions
diff --git a/src/weepinbell/storage/edn_storage.clj b/src/weepinbell/storage/edn_storage.clj index 042ff88..06e857a 100644 --- a/src/weepinbell/storage/edn_storage.clj +++ b/src/weepinbell/storage/edn_storage.clj @@ -4,7 +4,6 @@ (:require [fast-edn.core :as edn] [clojure.java.io :as io] [weepinbell.utils.url :refer [get-domain get-target get-path url=]] - [clojure.spec.alpha :as s] [weepinbell.storage.spec] [clojure.string :refer [join]])) @@ -68,6 +67,7 @@ #(cond->> % true (filter (partial domain-equal domain)) (some? path) (filter (partial path-equal path)) + true (sort-by (fn [x] (:modified (:webmention x)))) true vec)))) (defn first-line-empty? [path] diff --git a/src/weepinbell/storage/h2.clj b/src/weepinbell/storage/h2.clj index b42b5ba..dc81ce7 100644 --- a/src/weepinbell/storage/h2.clj +++ b/src/weepinbell/storage/h2.clj @@ -69,11 +69,15 @@ (sql/delete! ds :webmention {:hash hashcode})) (defn get-webmention-by-hash [ds hashcode] - (first (sql/find-by-keys ds :webmention {:hash hashcode}))) + (first (sql/find-by-keys ds :webmention + {:hash hashcode} + {:order-by [:lastmod :id]}))) (defn get-webmention-by-pair [ds source target] - (first (sql/find-by-keys ds :webmention {:wm_source source - :wm_target target}))) + (first (sql/find-by-keys ds :webmention + {:wm_source source + :wm_target target} + {:order-by [:lastmod :id]}))) (defn get-webmention ([ds hashcode] (some->> (get-webmention-by-hash ds hashcode) @@ -88,7 +92,8 @@ ([ds domain path] (let [keys (cond-> {:wm_target_domain domain} (some? path) (assoc :wm_target_path path))] - (->> (sql/find-by-keys ds :webmention keys) + (->> (sql/find-by-keys ds :webmention keys + {:order-by [:lastmod :id]}) (map (partial row->wrapped ds)))))) (defn- update-related! [ds wm_id data] |
