Skip to content

Commit

Permalink
fix(scheduler-utils): cache and return correct shape
Browse files Browse the repository at this point in the history
  • Loading branch information
TillaTheHun0 committed Dec 21, 2023
1 parent a91eb4b commit 931dd94
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
6 changes: 3 additions & 3 deletions scheduler-utils/src/client/in-memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ export function getByProcessWith ({ cache = internalCache }) {
}

export function setByProcessWith ({ cache = internalCache }) {
return async (process, { url, owner }, ttl) => {
return async (process, { url, address }, ttl) => {
if (!internalSize) return
return cache.set(process, { url, owner }, { ttl })
return cache.set(process, { url, address }, { ttl })
}
}

Expand All @@ -50,7 +50,7 @@ export function getByOwnerWith ({ cache = internalCache }) {
}

export function setByOwnerWith ({ cache = internalCache }) {
return async (owner, { url }, ttl) => {
return async (owner, url, ttl) => {
if (!internalSize) return
return cache.set(owner, { url, address: owner }, { ttl })
}
Expand Down
5 changes: 3 additions & 2 deletions scheduler-utils/src/locate.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ export function locateWith ({ loadProcessScheduler, cache }) {
if (cached) return cached
return loadProcessScheduler(process)
.then((scheduler) => {
const res = { url: scheduler.url, address: scheduler.owner }
return Promise.all([
cache.setByProcess(process, { url: scheduler.url, address: scheduler.owner }, scheduler.ttl),
cache.setByProcess(process, res, scheduler.ttl),
cache.setByOwner(scheduler.owner, scheduler.url, scheduler.ttl)
])
.then(() => ({ url: scheduler.url, address: scheduler.owner }))
.then(() => res)
})
})
}
4 changes: 2 additions & 2 deletions scheduler-utils/src/raw.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export function rawWith ({ loadScheduler, cache }) {
*/
return (address) =>
cache.getByOwner(address)
.then((url) => {
if (url) return { url }
.then((cached) => {
if (cached) return cached
return loadScheduler(address)
.then((scheduler) =>
cache.setByOwner(address, scheduler.url, scheduler.ttl)
Expand Down
4 changes: 2 additions & 2 deletions scheduler-utils/src/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export function validateWith ({ loadScheduler, cache }) {
*/
return (address) =>
cache.getByOwner(address)
.then((url) => {
if (url) return true
.then((cached) => {
if (cached) return true
return loadScheduler(address)
.then((scheduler) => cache.setByOwner(address, scheduler.url, scheduler.ttl))
.then(() => true)
Expand Down

0 comments on commit 931dd94

Please sign in to comment.