Skip to content

Commit

Permalink
fix: ignore draft & invalid deleted_at
Browse files Browse the repository at this point in the history
  • Loading branch information
flxxyz committed May 19, 2023
1 parent 8504baf commit 813acc3
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 81 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
key: ${{ runner.OS }}-deno-cache-dir-${{ hashFiles('deno.lock') }}
- name: Run deno cache command
if: steps.cache-deno-cache-dir.outputs.cache-hit != 'true'
run: deno cache src/index.ts
run: deno task cache
- name: Start MongoDB
uses: supercharge/mongodb-github-action@1.8.0
with:
Expand Down Expand Up @@ -120,7 +120,7 @@ jobs:
key: ${{ runner.OS }}-deno-cache-dir-${{ hashFiles('deno.lock') }}
- name: Run deno cache command
if: steps.cache-deno-cache-dir.outputs.cache-hit != 'true'
run: deno cache src/index.ts
run: deno task cache
- name: Start MongoDB
uses: supercharge/mongodb-github-action@1.8.0
with:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ FROM base as cache
COPY --chown=deno:deno . .

# Cache dependencies
RUN deno cache src/index.ts
RUN deno task cache

FROM base as runner

Expand Down
6 changes: 4 additions & 2 deletions deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
"test:integration:nip28": "deno test test/integration/features/nip-28/nip-28.feature.test.ts --no-check -A",
"test:integration:nip33": "deno test test/integration/features/nip-33/nip-33.feature.test.ts --no-check -A",
"git-hooks": "deno run --no-check=remote --allow-run=deno,git --allow-read --allow-write=.git-hooks https://deno.land/x/githooked/mod.ts install",
"bump": "deno run --allow-all .bump/bump.ts"
"bump": "deno run --allow-all .bump/bump.ts",
"cache": "deno cache src/index.ts --reload",
"force-cache": "deno cache src/index.ts --reload --lock-write"
},
"imports": {
"dotenv": "https://deno.land/x/dotenv@v3.2.0/mod.ts",
Expand All @@ -32,7 +34,7 @@
"joi": "https://cdn.skypack.dev/joi@17.7.0?dts",
"rxjs": "https://cdn.skypack.dev/rxjs@7.8.0?dts",
"chai-as-promised": "https://cdn.skypack.dev/chai-as-promised@7.1.1?dts",
"events": "node:events",
"events": "https://deno.land/std@0.177.0/node/events.ts",
"stream": "node:stream",
"stream/promises": "node:stream/promises",
"dns": "node:dns",
Expand Down
71 changes: 3 additions & 68 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/@types/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ export interface DBEvent {
event_tags: Tag[]
event_signature: Buffer
event_delegator?: Buffer | null
event_deduplication?: string | null
first_seen: Date
deleted_at?: Date
expires_at?: number
event_deduplication?: { 0: string; 1: number }[] | null
first_seen?: Date
deleted_at: string
expires_at: number
}

export interface CanonicalEvent {
Expand Down
2 changes: 1 addition & 1 deletion src/core-services/WebSocketServerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class WebSocketServerService extends ServiceClass {
debug('events.broadcast %s data: %o', clientAction, data)
if (data && typeof data !== 'undefined') {
// ignore draft
if (data.event_kind === 5 && data.event_signature) {
if (data?.event_signature?.toString() === '' || data?.deleted_at) {
return
}
adapter.emit(WebSocketServerAdapterEvent.Broadcast, toNostrEvent(data as DBEvent))
Expand Down
34 changes: 33 additions & 1 deletion src/database/models/Events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const EventSchema = new mongoose.Schema({
},
event_deduplication: [mongoose.Schema.Types.Mixed],
first_seen: { type: Date },
deleted_at: { type: Date },
deleted_at: { type: String },
expires_at: { type: Number },
})

Expand Down Expand Up @@ -70,6 +70,14 @@ EventSchema.index({ 'event_tags.0.1': 1 }, {
background: true,
sparse: true,
})
EventSchema.index({ 'event_tags.0.2': 1 }, {
background: true,
sparse: true,
})
EventSchema.index({ 'event_tags.0.3': 1 }, {
background: true,
sparse: true,
})
EventSchema.index({ 'event_tags.1.0': 1 }, {
background: true,
sparse: true,
Expand All @@ -78,6 +86,30 @@ EventSchema.index({ 'event_tags.1.1': 1 }, {
background: true,
sparse: true,
})
EventSchema.index({ 'event_tags.1.2': 1 }, {
background: true,
sparse: true,
})
EventSchema.index({ 'event_tags.1.3': 1 }, {
background: true,
sparse: true,
})
EventSchema.index({ 'event_tags.2.0': 1 }, {
background: true,
sparse: true,
})
EventSchema.index({ 'event_tags.2.1': 1 }, {
background: true,
sparse: true,
})
EventSchema.index({ 'event_tags.2.2': 1 }, {
background: true,
sparse: true,
})
EventSchema.index({ 'event_tags.2.3': 1 }, {
background: true,
sparse: true,
})
EventSchema.index({ 'remote_address': 1 }, {
background: true,
})
Expand Down
5 changes: 3 additions & 2 deletions src/repositories/event-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class EventRepository implements IEventRepository {

private async insert(event: Event) {
debug('inserting event: %o', event)
const row = applySpec({
const row: DBEvent = applySpec({
event_id: pipe(prop('id'), toBuffer),
event_pubkey: pipe(prop('pubkey'), toBuffer),
event_created_at: pipe(prop('created_at'), toNumber),
Expand All @@ -66,6 +66,7 @@ export class EventRepository implements IEventRepository {
prop(EventExpirationTimeMetadataKey as any),
always(null),
),
deleted_at: always(null),
})(event)

try {
Expand Down Expand Up @@ -191,7 +192,7 @@ export class EventRepository implements IEventRepository {
event_id: { $in: eventIdsToDelete.map(toBuffer) },
deleted_at: null,
},
{ deleted_at: new Date() },
{ deleted_at: new Date().toISOString() },
)
return ignoreUpdateConflicts(query)
}
Expand Down

0 comments on commit 813acc3

Please sign in to comment.