server: pass in resolved meta table to shouldBlockInstance
This should make it more friendly to use in places where the meta table has already been resolved for other reasons.
This commit is contained in:
parent
c02a03168d
commit
6583d0c43d
2 changed files with 4 additions and 5 deletions
|
@ -6,11 +6,10 @@ import { Meta } from '@/models/entities/meta.js';
|
|||
* Returns whether a specific host (punycoded) should be blocked.
|
||||
*
|
||||
* @param host punycoded instance host
|
||||
* @param meta a Promise contatining the information from the meta table (optional)
|
||||
* @param meta a resolved Meta table
|
||||
* @returns whether the given host should be blocked
|
||||
*/
|
||||
|
||||
export async function shouldBlockInstance(host: Instance['host'], meta: Promise<Meta> = fetchMeta()): Promise<boolean> {
|
||||
const { blockedHosts } = await meta;
|
||||
export async function shouldBlockInstance(host: Instance['host'], meta?: Meta): Promise<boolean> {
|
||||
const { blockedHosts } = meta ?? await fetchMeta();
|
||||
return blockedHosts.some(blockedHost => host === blockedHost || host.endsWith('.' + blockedHost));
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ const deadThreshold = 7 * DAY;
|
|||
*/
|
||||
export async function skippedInstances(hosts: Array<Instance['host']>): Promise<Array<Instance['host']>> {
|
||||
// Resolve the boolean promises before filtering
|
||||
const meta = fetchMeta();
|
||||
const meta = await fetchMeta();
|
||||
const shouldSkip = await Promise.all(hosts.map(host => shouldBlockInstance(host, meta)));
|
||||
const skipped = hosts.filter((_, i) => shouldSkip[i]);
|
||||
|
||||
|
|
Loading…
Reference in a new issue