Skip to content

Commit fd1e0aa

Browse files
CMR-7192: Use fingerprinted query in database instead of full normalized_query (#1217)
* CMR-7192: Use fingerprint instead of normalized-query in database
1 parent d5da4d9 commit fd1e0aa

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

common-app-lib/project.clj

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
[com.fasterxml.jackson.core/jackson-core "2.12.1"]
99
[com.fasterxml.jackson.dataformat/jackson-dataformat-cbor "2.12.1"]
1010
[compojure "1.6.1"]
11+
[digest "1.4.8"]
1112
[nasa-cmr/cmr-acl-lib "0.1.0-SNAPSHOT"]
1213
[nasa-cmr/cmr-common-lib "0.1.1-SNAPSHOT"]
1314
[nasa-cmr/cmr-elastic-utils-lib "0.1.0-SNAPSHOT"]

common-app-lib/src/cmr/common_app/services/ingest/subscription_common.clj

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"This contains the code for the scheduled subscription code to be shared
33
between metadata-db and ingest."
44
(:require
5-
[clojure.string :as string]))
5+
[clojure.string :as string]
6+
[digest :as digest]))
67

78
(defn normalize-parameters
89
"Returns a normalized url parameter string by splitting the string of parameters on '&' and
@@ -15,4 +16,5 @@
1516
(string/split #"&")
1617
sort
1718
(as-> $ (string/join "&" $))
18-
(string/trim))))
19+
string/trim
20+
digest/md5)))

common-app-lib/test/cmr/common_app/test/services/ingest/subscription.clj

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77
"Query normalization, should be sorted parameters"
88
(testing "With a leading question mark"
99
(let [query "provider=PROV1&instrument=1B&instrument=2B"
10-
expected "instrument=1B&instrument=2B&provider=PROV1"
10+
expected "bc71e563ac03a05d7c557608f868ce6a"
1111
actual (sub-common/normalize-parameters query)]
1212
(is (= expected actual))))
1313
(testing "Without a leading question mark"
1414
(let [query "provider=PROV1&instrument=1B&instrument=2B"
15-
expected "instrument=1B&instrument=2B&provider=PROV1"
15+
expected "bc71e563ac03a05d7c557608f868ce6a"
1616
actual (sub-common/normalize-parameters query)]
1717
(is (= expected actual))))
1818
(testing "Empty string"
1919
(let [query ""
20-
expected ""
20+
expected "d41d8cd98f00b204e9800998ecf8427e"
2121
actual (sub-common/normalize-parameters query)]
2222
(is (= expected actual)))))

metadata-db-app/src/cmr/metadata_db/migrations/074_add_normalized_to_subscription_table.clj

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
;; applications can assume the normalized query is the same despite changes
4242
;; in query order or other such nominal differences. Simple string compair
4343
;; can be used on the normalized query.
44-
(helper/sql "alter table cmr_subscriptions add normalized_query VARCHAR2(4000)")
44+
(helper/sql "alter table cmr_subscriptions add normalized_query VARCHAR2(64)")
4545
(populate-new-column)
4646
(create-subscription-index))
4747

0 commit comments

Comments
 (0)