Skip to content

Fetch record count endpoints #50

@whittlbc

Description

@whittlbc

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 nsps array from being longer than 50 entries

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 ids array from being longer than 50 entries

Response:

{
    uid1: { count: 100, updatedAt: '...' },
    uid2: { count: 200, updatedAt: '...' }
    ...
}

Strategy:

  • Create a new live object version service getTablePathsForLiveObjectVersions that returns a list of table paths for a list of live object version uids (extract table path from config.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
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions