Browse Source

Introduce `ProcessDelete` method in `database` package; update `go.mod` with `database.orly` module replacements across packages

main
mleku 4 months ago
parent
commit
5a640e7502
No known key found for this signature in database
  1. 5
      app/handle-event.go
  2. 1
      pkg/acl/go.mod
  3. 1
      pkg/crypto/go.mod
  4. 1
      pkg/database/go.mod
  5. 78
      pkg/database/process-delete.go
  6. 1
      pkg/utils/go.mod

5
app/handle-event.go

@ -6,6 +6,7 @@ import ( @@ -6,6 +6,7 @@ import (
"strings"
"encoders.orly/envelopes/eventenvelope"
"encoders.orly/kind"
"lol.mleku.dev/chk"
"lol.mleku.dev/log"
utils "utils.orly"
@ -53,6 +54,10 @@ func (l *Listener) HandleEvent(c context.Context, msg []byte) ( @@ -53,6 +54,10 @@ func (l *Listener) HandleEvent(c context.Context, msg []byte) (
return
}
return
}
// if the event is a delete, process the delete
if env.E.Kind == kind.EventDeletion.K {
}
// check if the event was deleted
//

1
pkg/acl/go.mod

@ -5,6 +5,7 @@ go 1.25.0 @@ -5,6 +5,7 @@ go 1.25.0
replace (
crypto.orly => ../crypto
encoders.orly => ../encoders
database.orly => ../database
interfaces.orly => ../interfaces
next.orly.dev => ../../
protocol.orly => ../protocol

1
pkg/crypto/go.mod

@ -26,6 +26,7 @@ require ( @@ -26,6 +26,7 @@ require (
replace (
acl.orly => ../acl
crypto.orly => ../crypto
database.orly => ../database
encoders.orly => ../encoders
interfaces.orly => ../interfaces
next.orly.dev => ../../

1
pkg/database/go.mod

@ -5,6 +5,7 @@ go 1.25.0 @@ -5,6 +5,7 @@ go 1.25.0
replace (
acl.orly => ../acl
crypto.orly => ../crypto
database.orly => ../database
encoders.orly => ../encoders
interfaces.orly => ../interfaces
next.orly.dev => ../../

78
pkg/database/process-delete.go

@ -0,0 +1,78 @@ @@ -0,0 +1,78 @@
package database
import (
"context"
"sort"
"database.orly/indexes/types"
"encoders.orly/event"
"encoders.orly/filter"
"encoders.orly/ints"
"encoders.orly/kind"
"encoders.orly/tag"
"interfaces.orly/store"
"lol.mleku.dev/chk"
)
func (d *D) ProcessDelete(ev *event.E, admins [][]byte) (err error) {
eTags := ev.Tags.GetAll([]byte("e"))
aTags := ev.Tags.GetAll([]byte("a"))
kTags := ev.Tags.GetAll([]byte("k"))
// if there are no e or a tags, we assume the intent is to delete all
// replaceable events of the kinds specified by the k tags for the pubkey of
// the delete event.
if len(eTags) == 0 && len(aTags) == 0 {
// parse the kind tags
var kinds []*kind.K
for _, k := range kTags {
kv := k.Value()
iv := ints.New(0)
if _, err = iv.Unmarshal(kv); chk.E(err) {
continue
}
kinds = append(kinds, kind.New(iv.N))
}
var idxs []Range
if idxs, err = GetIndexesFromFilter(
&filter.F{
Authors: tag.NewFromBytesSlice(ev.Pubkey),
Kinds: kind.NewS(kinds...),
},
); chk.E(err) {
return
}
var sers types.Uint40s
for _, idx := range idxs {
var s types.Uint40s
if s, err = d.GetSerialsByRange(idx); chk.E(err) {
return
}
sers = append(sers, s...)
}
if len(sers) > 0 {
var idPkTss []*store.IdPkTs
var tmp []*store.IdPkTs
if tmp, err = d.GetFullIdPubkeyBySerials(sers); chk.E(err) {
return
}
idPkTss = append(idPkTss, tmp...)
// sort by timestamp, so the first is the oldest, so we can collect
// all of them until the delete event created_at.
sort.Slice(
idPkTss, func(i, j int) bool {
return idPkTss[i].Ts > idPkTss[j].Ts
},
)
for _, v := range idPkTss {
if v.Ts < ev.CreatedAt {
if err = d.DeleteEvent(
context.Background(), v.Id,
); chk.E(err) {
continue
}
}
}
}
}
return
}

1
pkg/utils/go.mod

@ -31,6 +31,7 @@ require ( @@ -31,6 +31,7 @@ require (
replace (
acl.orly => ../acl
crypto.orly => ../crypto
database.orly => ../database
encoders.orly => ../encoders
interfaces.orly => ../interfaces
next.orly.dev => ../../

Loading…
Cancel
Save