Skip to content

Commit

Permalink
feat: supporting nip-09, accepting 1 filter per req message, using ag…
Browse files Browse the repository at this point in the history
…gregation pipeline on req.:
  • Loading branch information
kehiy committed Jan 12, 2025
1 parent 87747c6 commit b9a6822
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions repository/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func (h *Handler) DeleteByID(id string, kind types.Kind) error {
filter := bson.D{
deleteFilter := bson.D{
{Key: "id", Value: id},
}

Expand All @@ -31,7 +31,7 @@ func (h *Handler) DeleteByID(id string, kind types.Kind) error {
ctx, cancel := context.WithTimeout(context.Background(), h.db.QueryTimeout)
defer cancel()

_, err := coll.UpdateOne(ctx, filter, update)
_, err := coll.UpdateOne(ctx, deleteFilter, update)
if err != nil {
_, err := h.grpc.AddLog(context.Background(),
"database error while removing event", err.Error())
Expand All @@ -52,7 +52,7 @@ func (h *Handler) DeleteByFilter(f *filter.Filter) error {
// helps us ti prevent multiple database calls and it would help us to do the operation faster.
// to do the same thing for deletion we need to filter the documents with $match, then update the
// fields of deleted event to null (expect the `id` since its unique index to prevent overwrites) with $unset
// then we apply them to collection using $merge.
// then we apply them to collection using $merge.
// although we can't use multiple $merge's on one pipeline and we must have
// only one merge at the end of pipeline commands. also, $unionWith is restricted to be used with $merge.

Expand All @@ -62,7 +62,7 @@ func (h *Handler) DeleteByFilter(f *filter.Filter) error {
// we are dealing with filters since filters contain a list of kinds
// (which can be empty and we are then forced to query all collections)

// 2. when we delete an event we $unset all fields expect `id`.
// 2. when we delete an event we $unset all fields expect `id`.
// when we make a query to read from database, we ignore fields which
// their fields are null. and when we write new events we prevent overwriting
// events with duplicated `id`. so we can handle the deletion properly.
Expand Down

0 comments on commit b9a6822

Please sign in to comment.