Skip to content

Commit

Permalink
Add verbose logging to palomar handle updates (#384)
Browse files Browse the repository at this point in the history
This change adds verbose logging to Palomar handle updates and resolves
handles from PLC when seeing an update instead of trusting the handle
from the event.
  • Loading branch information
ericvolp12 authored Oct 10, 2023
2 parents a38a41d + 3145474 commit adea82e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
7 changes: 6 additions & 1 deletion search/firehose.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,12 @@ func (s *Server) RunIndexer(ctx context.Context) error {

},
RepoHandle: func(evt *comatproto.SyncSubscribeRepos_Handle) error {
if err := s.updateUserHandle(ctx, evt.Did, evt.Handle); err != nil {
did, err := syntax.ParseDID(evt.Did)
if err != nil {
s.logger.Error("bad DID in RepoHandle event", "did", evt.Did, "handle", evt.Handle, "seq", evt.Seq, "err", err)
return nil
}
if err := s.updateUserHandle(ctx, did, evt.Handle); err != nil {
// TODO: handle this case (instead of return nil)
s.logger.Error("failed to update user handle", "did", evt.Did, "handle", evt.Handle, "seq", evt.Seq, "err", err)
}
Expand Down
24 changes: 20 additions & 4 deletions search/indexing.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

appbsky "github.com/bluesky-social/indigo/api/bsky"
"github.com/bluesky-social/indigo/atproto/identity"
"github.com/bluesky-social/indigo/atproto/syntax"
"github.com/bluesky-social/indigo/util"
"github.com/ipfs/go-cid"

Expand Down Expand Up @@ -132,14 +133,29 @@ func (s *Server) indexProfile(ctx context.Context, ident *identity.Identity, rec
return nil
}

func (s *Server) updateUserHandle(ctx context.Context, did, handle string) error {
log := s.logger.With("repo", did, "op", "updateUserHandle", "handle", handle)
func (s *Server) updateUserHandle(ctx context.Context, did syntax.DID, handle string) error {
log := s.logger.With("repo", did.String(), "op", "updateUserHandle", "handle_from_event", handle)

err := s.dir.Purge(ctx, did.AtIdentifier())
if err != nil {
log.Warn("failed to purge DID from directory", "err", err)
return err
}

ident, err := s.dir.LookupDID(ctx, did)
if err != nil {
log.Warn("failed to lookup DID in directory", "err", err)
return err
}

log.Info("updating user handle", "handle_from_dir", handle)

b, err := json.Marshal(map[string]any{
"script": map[string]any{
"source": "ctx._source.handle = params.handle",
"lang": "painless",
"params": map[string]any{
"handle": handle,
"handle": ident.Handle,
},
},
})
Expand All @@ -150,7 +166,7 @@ func (s *Server) updateUserHandle(ctx context.Context, did, handle string) error

req := esapi.UpdateRequest{
Index: s.profileIndex,
DocumentID: did,
DocumentID: did.String(),
Body: bytes.NewReader(b),
}

Expand Down

0 comments on commit adea82e

Please sign in to comment.