Skip to content

Commit

Permalink
feat(database): delete things from meili
Browse files Browse the repository at this point in the history
  • Loading branch information
yjl9903 committed Jan 29, 2024
1 parent e31c583 commit 87fb32d
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions packages/database/src/meilisearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,18 @@ export function connectMeiliSearch(host: string, key: string): MeiliSearch {

export async function insertResourceDocuments(client: MeiliSearch, resources: Resource[]) {
const resp = await client.index('resources').addDocuments(
resources.map((d) => ({
...d,
// Map to number, used for lt or gt
createdAt: d.createdAt!.getTime(),
fetchedAt: d.fetchedAt!.getTime()
}))
resources
.filter((r) => !r.isDeleted)
.map((d) => ({
...d,
// Map to number, used for lt or gt
createdAt: d.createdAt!.getTime(),
fetchedAt: d.fetchedAt!.getTime()
}))
);
const deleted = resources.filter((r) => r.isDeleted);
if (deleted.length > 0) {
await client.index('resources').deleteDocuments(deleted.map((r) => r.id));
}
return resp;
}

0 comments on commit 87fb32d

Please sign in to comment.