core/utils/Fetch.ts
2021-01-08 22:17:59 +09:00

22 lines
538 B
TypeScript

import DataLoader from 'dataloader'
import * as Query from './Query'
const Fetch = {
bot: new DataLoader(
async (ids: string[]) =>
(await Promise.all(ids.map((el: string) => Query.getBot(el)))).map(row => ({ ...row })),
{
batchScheduleFn: callback => setTimeout(callback, 1000),
}
),
user: new DataLoader(
async (ids: string[]) =>
(await Promise.all(ids.map((el: string) => Query.getUser(el)))).map(row => ({ ...row })),
{
batchScheduleFn: callback => setTimeout(callback, 1000),
}
),
}
export default Fetch