Skip to content

Commit

Permalink
identity: remove pubkey caching (ParsedPublicKey)
Browse files Browse the repository at this point in the history
This turned out to be a false economy: the key was most often not used
so the parsing was a waste of resources.

Could imagine adding less-eager caching being added back in at some
point, though some external cache/LRU probably makes the most sense.
  • Loading branch information
bnewbold committed Mar 7, 2024
1 parent b4f5785 commit 1159c19
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 19 deletions.
10 changes: 0 additions & 10 deletions atproto/identity/base_directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ func (d *BaseDirectory) LookupHandle(ctx context.Context, h syntax.Handle) (*Ide
}
ident.Handle = declared

// optimistic pre-parsing of public key
pk, err := ident.PublicKey()
if nil == err {
ident.ParsedPublicKey = pk
}
return &ident, nil
}

Expand Down Expand Up @@ -88,11 +83,6 @@ func (d *BaseDirectory) LookupDID(ctx context.Context, did syntax.DID) (*Identit
}
}

// optimistic pre-parsing of public key
pk, err := ident.PublicKey()
if nil == err {
ident.ParsedPublicKey = pk
}
return &ident, nil
}

Expand Down
9 changes: 0 additions & 9 deletions atproto/identity/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ type Identity struct {
AlsoKnownAs []string
Services map[string]Service
Keys map[string]Key

// If a valid atproto repo signing public key was parsed, it can be cached here. This is a nullable/optional field (crypto.PublicKey is an interface). Calling code should use [Identity.PublicKey] instead of accessing this member.
ParsedPublicKey crypto.PublicKey
}

type Key struct {
Expand Down Expand Up @@ -161,9 +158,6 @@ func ParseIdentity(doc *DIDDocument) Identity {
//
// Note that [crypto.PublicKey] is an interface, not a concrete type.
func (i *Identity) PublicKey() (crypto.PublicKey, error) {
if i.ParsedPublicKey != nil {
return i.ParsedPublicKey, nil
}
if i.Keys == nil {
return nil, fmt.Errorf("identity has no atproto public key attached")
}
Expand All @@ -176,9 +170,6 @@ func (i *Identity) PublicKey() (crypto.PublicKey, error) {
//
// Note that [crypto.PublicKey] is an interface, not a concrete type.
func (i *Identity) PublicKeyFor(forKey string) (crypto.PublicKey, error) {
if i.ParsedPublicKey != nil {
return i.ParsedPublicKey, nil
}
if i.Keys == nil {
return nil, fmt.Errorf("identity has no atproto public key attached")
}
Expand Down

0 comments on commit 1159c19

Please sign in to comment.