perf: use server namespace to simplify kv querying (#1246)

zio/stable
Daniel Roe 2023-01-17 11:44:15 +01:00 committed by GitHub
parent a91d3c1e92
commit 21b277ffce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 4 deletions

View File

@ -55,7 +55,8 @@ async function fetchAppInfo(origin: string, server: string) {
}
export async function getApp(origin: string, server: string) {
const key = `servers:${origin.replace(/[^\w\d]/g, '-')}:${server}.json`
const host = origin.replace(/^https?:\/\//, '').replace(/[^\w\d]/g, '-')
const key = `servers:v2:${server}:${host}.json`.toLowerCase()
try {
if (await storage.hasItem(key))
@ -70,16 +71,16 @@ export async function getApp(origin: string, server: string) {
}
export async function deleteApp(server: string) {
const keys = (await storage.getKeys('servers:')).filter(k => k.endsWith(`${server}.json`))
const keys = (await storage.getKeys(`servers:v2:${server}:`))
for (const key of keys)
await storage.removeItem(key)
}
export async function listServers() {
const keys = await storage.getKeys('servers:')
const keys = await storage.getKeys('servers:v2:')
const servers = new Set<string>()
for await (const key of keys) {
const id = key.split(':').pop()!.replace(/\.json$/, '')
const id = key.split(':')[2]
if (id)
servers.add(id.toLocaleLowerCase())
}