-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
We need 2 new endpoints, each for fetching the latest record counts for a particular resource.
1) Namespace Record Counts
Endpoint: POST /namespaces/record-counts
Auth: None
Payload:
{
nsps: ['allov2', 'station', ...]
}Payload Validations
- prevent
nspsarray from being longer than50entries
Response:
{
allov2: { count: 1311, updatedAt: '...' },
station: { count: 6116, updatedAt: '...' }
...
}
Strategy:
const recordCounts = await getCachedNamespaceRecordCounts(payload.nsps)2) Live Object Version Record Counts
Endpoint: POST /live-object-versions/record-counts
Auth: None
Payload:
{
ids: ['uid1', 'uid2', ...]
}Payload Validations
- prevent
idsarray from being longer than50entries
Response:
{
uid1: { count: 100, updatedAt: '...' },
uid2: { count: 200, updatedAt: '...' }
...
}
Strategy:
- Create a new live object version service
getTablePathsForLiveObjectVersionsthat returns a list of table paths for a list of live object version uids (extract table path fromconfig.table). - Create map of
{ <tablePath>: <uid> } - Use
getCachedRecordCounts(liveObjectVersionTablePaths)to get a map of record counts where keys are table paths - Create new map that swaps the table path keys for uids (leveraging map you created in bullet 2)
Local Testing
Best way to test this locally will be to open up a scrap.ts file and manually put some entries in your local redis instance like so:
// import shit from shared
async function cacheLiveObjectVersionRecordCounts(recordCounts: StringKeyMap[]) {
const cacheUpdates = {}
for (const { tablePath, count } of recordCounts) {
cacheUpdates[tablePath] = JSON.stringify({
count,
updatedAt: new Date().toISOString()
})
}
await updateRecordCountsCache(cacheUpdates)
}
async function cacheNamespaceRecordCounts(recordCounts: StringKeyMap[]) {
const cacheUpdates = {}
for (const { nsp, count } of recordCounts) {
cacheUpdates[nsp] = JSON.stringify({
count,
updatedAt: new Date().toISOString()
})
}
await updateNamespaceRecordCountsCache(cacheUpdates)
}
// Manually set shit in redis.
// For the live object version table paths, just query your `live_object_versions` table
// and pick some off of those records that already exist.
;(async () => {
await cacheLiveObjectVersionRecordCounts([
{ tablePath: '...', count: 100 },
{ tablePath: '...', count: 200 },
])
await cacheNamespaceRecordCounts([
{ nsp: 'allov2', count: 100 },
{ nsp: 'station', count: 200 },
])
})()Metadata
Metadata
Assignees
Labels
No labels