traxxx-web/src/cache.js

28 lines
561 B
JavaScript

import redis from './redis.js';
export async function getIdsBySlug(slugs, domain, toMap) {
if (!slugs) {
return [];
}
const ids = await Promise.all(slugs.map(async (slug) => {
if (!slug) {
return null;
}
if (typeof slug === 'number') {
return slug; // already an ID, tags like 69 should be a string at this stage
}
const id = await redis.hGet(`traxxx:${domain}:id_by_slug`, slug);
return Number(id);
}));
if (toMap) {
return Object.fromEntries(slugs.map((slug, index) => [slug, ids[index]]));
}
return ids.filter(Boolean);
}