renewProfiles

tcmts.hub.renewProfiles · #wfqdq67o · term · runs on the server

uses tcmts.hub.people, which uses tcmts.server.table, which uses tcmts.server.Table, which uses #tcm/host (database)

Read again the profiles of people the hub knows whose profile it read a day ago or more, or never: most at a time. One whose repository doesn't answer keeps what it had, until the next day. How many it read.

import { people, profileOf } from "#codebase/tcmts/hub";
import type { Someone } from "#codebase/tcmts/hub";

export async function renewProfiles(most = 20): Promise<number> {
  const day = 24 * 60 * 60 * 1000;
  const due = (await people.find())
    .filter((p) => !p.value.profileAt || Date.now() - p.value.profileAt.getTime() > day)
    .slice(0, most);
  for (const p of due) {
    let got: Omit<Someone, "did"> | undefined;
    try {
      got = await profileOf(p.value.did);
    } catch {}
    await people.update(p.id, (v) => {
      if (!got) return { ...v, profileAt: new Date() };
      const { name: _, bio: __, avatar: ___, ...rest } = v;
      return { ...rest, ...got, profileAt: new Date() };
    });
  }
  return due.length;
}

uses

used by