add dedupe action
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
"version": "1.0.0",
|
||||
"dependencies": {
|
||||
"eventemitter3": "^5.0.1",
|
||||
"fast-deep-equal": "^3.1.3",
|
||||
"knex": "^3.1.0",
|
||||
"knex-pglite": "^0.12.0",
|
||||
"pg": "^8.16.3",
|
||||
|
||||
@@ -1,8 +1,15 @@
|
||||
import { EventEmitter } from 'eventemitter3';
|
||||
import deepEqual from 'fast-deep-equal';
|
||||
|
||||
import { DatabaseService, tableNames, type TableRow } from '../database/database.ts';
|
||||
|
||||
import type { Document, DocumentSearchOptions, DocumentUpsert, DocumentUpsertEvent } from './documents.schemas.ts';
|
||||
import {
|
||||
documentUpsertEventSchema,
|
||||
type Document,
|
||||
type DocumentSearchOptions,
|
||||
type DocumentUpsert,
|
||||
type DocumentUpsertEvent,
|
||||
} from './documents.schemas.ts';
|
||||
import { buildMetaCondition } from './documents.query.ts';
|
||||
|
||||
import type { Services } from '#root/utils/services.ts';
|
||||
@@ -34,6 +41,11 @@ class DocumentsService extends EventEmitter<DocumentEvents> {
|
||||
updatedAt: new Date().toISOString(),
|
||||
deletedAt: null,
|
||||
};
|
||||
const currentUpsert = documentUpsertEventSchema.parse(current);
|
||||
const toInsertUpsert = documentUpsertEventSchema.parse(toInsert);
|
||||
if (deepEqual(currentUpsert, toInsertUpsert)) {
|
||||
return;
|
||||
}
|
||||
await db(tableNames.documents).update(toInsert).where({
|
||||
uri: document.uri,
|
||||
type: document.type,
|
||||
|
||||
3
pnpm-lock.yaml
generated
3
pnpm-lock.yaml
generated
@@ -55,6 +55,9 @@ importers:
|
||||
eventemitter3:
|
||||
specifier: ^5.0.1
|
||||
version: 5.0.1
|
||||
fast-deep-equal:
|
||||
specifier: ^3.1.3
|
||||
version: 3.1.3
|
||||
knex:
|
||||
specifier: ^3.1.0
|
||||
version: 3.1.0(pg@8.16.3)
|
||||
|
||||
Reference in New Issue
Block a user