Improve performance

This commit is contained in:
Melroy van den Berg 2025-04-25 01:10:36 +02:00
parent 8e5a08ab5f
commit e56d6c9c41
No known key found for this signature in database
GPG key ID: 71D11FF23454B9D7
2 changed files with 5 additions and 3 deletions

View file

@ -187,6 +187,8 @@ func (r *Resolver) fetchActorData(actorURL string) ([]byte, error) {
} }
// extractPublicKey extracts the public key ID from actor data // extractPublicKey extracts the public key ID from actor data
// TODO: We are actually now extracting the ID not the public key pem....
// Lets see if we can improve this, without breaking the signing.
func (r *Resolver) extractPublicKey(data []byte) (string, error) { func (r *Resolver) extractPublicKey(data []byte) (string, error) {
// Try to find the attributedTo URL // Try to find the attributedTo URL
actorURL := gjson.GetBytes(data, "attributedTo").String() actorURL := gjson.GetBytes(data, "attributedTo").String()

View file

@ -201,12 +201,12 @@ func (r *Resolver) resolveCanonicalActivityPub(objectURL string, depth int) (str
return "", fmt.Errorf("too many canonical redirects (possible loop)") return "", fmt.Errorf("too many canonical redirects (possible loop)")
} }
fmt.Printf("Fetching ActivityPub object for canonical resolution: %s\n", objectURL) fmt.Printf("Fetching ActivityPub object for canonical resolution: %s\n", objectURL)
jsonData, err := r.fetchActivityPubObjectRaw(objectURL) raw, err := r.fetchActivityPubObjectRaw(objectURL)
if err != nil { if err != nil {
return "", err return "", err
} }
var data map[string]interface{} var data map[string]interface{}
if err := json.Unmarshal(jsonData, &data); err != nil { if err := json.Unmarshal(raw, &data); err != nil {
return "", fmt.Errorf("error parsing ActivityPub JSON: %v", err) return "", fmt.Errorf("error parsing ActivityPub JSON: %v", err)
} }
idVal, ok := data["id"].(string) idVal, ok := data["id"].(string)
@ -215,7 +215,7 @@ func (r *Resolver) resolveCanonicalActivityPub(objectURL string, depth int) (str
return r.resolveCanonicalActivityPub(idVal, depth+1) return r.resolveCanonicalActivityPub(idVal, depth+1)
} }
// If no id or already canonical, format and return using helpers.go // If no id or already canonical, format and return using helpers.go
formatted, err := formatResult(jsonData) formatted, err := formatResult(raw)
if err != nil { if err != nil {
return "", fmt.Errorf("error formatting ActivityPub object: %v", err) return "", fmt.Errorf("error formatting ActivityPub object: %v", err)
} }