From f81c7ac544be0f7d3eef4b7f71286510141c121a Mon Sep 17 00:00:00 2001 From: Jaz Volpert Date: Tue, 10 Oct 2023 04:44:44 +0000 Subject: [PATCH 1/3] Add verbose logging to handle updates --- search/indexing.go | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/search/indexing.go b/search/indexing.go index cc54f0373..a671cb670 100644 --- a/search/indexing.go +++ b/search/indexing.go @@ -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" @@ -132,14 +133,35 @@ 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, didStr, handle string) error { + log := s.logger.With("repo", didStr, "op", "updateUserHandle", "handle_from_event", handle) + + did, err := syntax.ParseAtIdentifier(didStr) + if err != nil || did == nil { + log.Warn("failed to parse DID", "err", err) + return err + } + + err = s.dir.Purge(ctx, *did) + if err != nil { + log.Warn("failed to purge DID from directory", "err", err) + return err + } + + ident, err := s.dir.LookupDID(ctx, syntax.DID(didStr)) + 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, }, }, }) @@ -150,7 +172,7 @@ func (s *Server) updateUserHandle(ctx context.Context, did, handle string) error req := esapi.UpdateRequest{ Index: s.profileIndex, - DocumentID: did, + DocumentID: didStr, Body: bytes.NewReader(b), } From a9092c7f22a2e74791468225bc3a2ec8f844168c Mon Sep 17 00:00:00 2001 From: Jaz Volpert Date: Tue, 10 Oct 2023 04:55:16 +0000 Subject: [PATCH 2/3] Pass a DID to handler --- search/firehose.go | 7 ++++++- search/indexing.go | 17 ++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/search/firehose.go b/search/firehose.go index 58ea390b4..5b71a5ba5 100644 --- a/search/firehose.go +++ b/search/firehose.go @@ -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) } diff --git a/search/indexing.go b/search/indexing.go index a671cb670..4729cb02d 100644 --- a/search/indexing.go +++ b/search/indexing.go @@ -133,22 +133,17 @@ func (s *Server) indexProfile(ctx context.Context, ident *identity.Identity, rec return nil } -func (s *Server) updateUserHandle(ctx context.Context, didStr, handle string) error { - log := s.logger.With("repo", didStr, "op", "updateUserHandle", "handle_from_event", 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) - did, err := syntax.ParseAtIdentifier(didStr) - if err != nil || did == nil { - log.Warn("failed to parse DID", "err", err) - return err - } - - err = s.dir.Purge(ctx, *did) + didID := syntax.AtIdentifier{Inner: did} + err := s.dir.Purge(ctx, didID) if err != nil { log.Warn("failed to purge DID from directory", "err", err) return err } - ident, err := s.dir.LookupDID(ctx, syntax.DID(didStr)) + ident, err := s.dir.LookupDID(ctx, did) if err != nil { log.Warn("failed to lookup DID in directory", "err", err) return err @@ -172,7 +167,7 @@ func (s *Server) updateUserHandle(ctx context.Context, didStr, handle string) er req := esapi.UpdateRequest{ Index: s.profileIndex, - DocumentID: didStr, + DocumentID: did.String(), Body: bytes.NewReader(b), } From 314547482979917e9054d5bf07c99445084e5dfc Mon Sep 17 00:00:00 2001 From: Jaz Volpert Date: Tue, 10 Oct 2023 05:13:56 +0000 Subject: [PATCH 3/3] Use new AtIdentifier helper --- search/indexing.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/search/indexing.go b/search/indexing.go index 4729cb02d..042961dff 100644 --- a/search/indexing.go +++ b/search/indexing.go @@ -136,8 +136,7 @@ func (s *Server) indexProfile(ctx context.Context, ident *identity.Identity, rec 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) - didID := syntax.AtIdentifier{Inner: did} - err := s.dir.Purge(ctx, didID) + err := s.dir.Purge(ctx, did.AtIdentifier()) if err != nil { log.Warn("failed to purge DID from directory", "err", err) return err