Skip to content

Commit

Permalink
feat(bundles filters): canonicalize bundle filter string PE-3769
Browse files Browse the repository at this point in the history
Use a canonical JSON representation for filters to avoid storing the
same filter multiple times in the DB.
  • Loading branch information
djwhitt committed Jul 18, 2023
1 parent ca3cfd8 commit 19ea253
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"fastq": "^1.13.0",
"fs-extra": "^11.1.0",
"graphql": "^16.5.0",
"json-canonicalize": "^1.0.6",
"middleware-async": "^1.3.5",
"msgpackr": "^1.6.2",
"node-cache": "^5.1.2",
Expand Down
11 changes: 5 additions & 6 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import dotenv from 'dotenv';
import { canonicalize } from 'json-canonicalize';
import crypto from 'node:crypto';

import { createFilter } from './filters.js';
Expand Down Expand Up @@ -52,16 +53,14 @@ export const ADMIN_API_KEY = env.varOrDefault(
if (env.varOrUndefined('ADMIN_API_KEY') === undefined) {
log.info('Using a random admin key since none was set', { ADMIN_API_KEY });
}
export const ANS104_UNBUNDLE_FILTER_STRING = env.varOrDefault(
'ANS104_UNBUNDLE_FILTER',
'{"never": true}',
export const ANS104_UNBUNDLE_FILTER_STRING = canonicalize(
JSON.parse(env.varOrDefault('ANS104_UNBUNDLE_FILTER', '{"never": true}')),
);
export const ANS104_UNBUNDLE_FILTER = createFilter(
JSON.parse(ANS104_UNBUNDLE_FILTER_STRING),
);
export const ANS104_INDEX_FILTER_STRING = env.varOrDefault(
'ANS104_INDEX_FILTER',
'{"never": true}',
export const ANS104_INDEX_FILTER_STRING = canonicalize(
JSON.parse(env.varOrDefault('ANS104_INDEX_FILTER', '{"never": true}')),
);
export const ANS104_INDEX_FILTER = createFilter(
JSON.parse(ANS104_INDEX_FILTER_STRING),
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4040,6 +4040,11 @@ json-buffer@3.0.0:
resolved "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.0.tgz"
integrity sha512-CuUqjv0FUZIdXkHPI8MezCnFCdaTAacej1TZYulLoAg1h/PhwkdXFN4V/gzY4g+fMBCOV2xF+rp7t2XD2ns/NQ==

json-canonicalize@^1.0.6:
version "1.0.6"
resolved "https://registry.yarnpkg.com/json-canonicalize/-/json-canonicalize-1.0.6.tgz#c63dc9b909db322fec058320a0f81aef6569b257"
integrity sha512-kP2iYpOS5SZHYhIaR1t9oG80d4uTY3jPoaBj+nimy3njtJk8+sRsVatN8pyJRDRtk9Su3+6XqA2U8k0dByJBUQ==

json-parse-even-better-errors@^2.3.0:
version "2.3.1"
resolved "https://registry.yarnpkg.com/json-parse-even-better-errors/-/json-parse-even-better-errors-2.3.1.tgz#7c47805a94319928e05777405dc12e1f7a4ee02d"
Expand Down

0 comments on commit 19ea253

Please sign in to comment.