Skip to content

Commit

Permalink
Fixed default Model cache key generation issue (#1084)
Browse files Browse the repository at this point in the history
* fix(core): fixed an default cache key generation for varying request methods ie. GET & POST

The default generator was ignoring variances between GET & POST methods. This caused POST requests
to get cached incorrectly.

* chore: added changeset

* chore: trigger ci

---------

Co-authored-by: Rich Gwozdz <[email protected]>
  • Loading branch information
Jake13f and rgwozdz authored Aug 13, 2024
1 parent dff2c6e commit 793a97f
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 126 deletions.
5 changes: 5 additions & 0 deletions .changeset/silent-dodos-tie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@koopjs/koop-core': patch
---

Fixed default cache key generation to support POST requests
15 changes: 14 additions & 1 deletion packages/core/src/data-provider/extend-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,20 @@ module.exports = function extendModel(
if (providerKeyGenerator) {
return providerKeyGenerator(req);
}
return hasher(req.url).toString();

const url = new URL(req.url, `http://${req.headers.host}`);
const base = url.origin + url.pathname;
const params = Object.assign({}, req.query, req.body);

return (
hasher
// Use larger hash here to have less collisions. Parameters can be quite large since
// geometries and OBJECTID sets can be passed in
.bigInt(`${base}::${JSON.stringify(params)}`, {
size: 128,
})
.toString()
);
}

async #authorizeRequest(req) {
Expand Down
Loading

0 comments on commit 793a97f

Please sign in to comment.