Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

feat: gateway.ContentPathKey as affinity key #46

Merged
merged 2 commits into from
Feb 24, 2023
Merged

Conversation

hacdias
Copy link
Contributor

@hacdias hacdias commented Feb 24, 2023

Context keys should not be strings: https://pkg.go.dev/context#WithValue. I'm not sure whether changing it to interface{} - to allow for custom types - will prevent bugs, but I hope so. Refactored it so we dont use interface{}@lidel

this removes the need for polluting public API with interface{}
@lidel lidel changed the title fix: AffinityKey should not be string feat: gateway.ContentPathKey as affinity key Feb 24, 2023
Comment on lines +140 to +158
// https://github.com/ipfs/bifrost-gateway/issues/53#issuecomment-1442732865
if affG := ctx.Value(gateway.ContentPathKey); affG != nil {
contentPath := affG.(ipath.Path).String()

// Using exact content path seems to work better for initial website loads
// because it groups all blocks related to the single file,
// but at the same time spreads files across multiple L1s
// which removes the risk of specific L1 becoming a cache hot spot for
// websites with huge DAG like /ipns/en.wikipedia-on-ipfs.org
return contentPath

/* TODO: if we ever want to revisit, and group per root CID of entire DAG:
const contentRootIdx = 2
if parts := strings.Split(contentPath, "/"); len(parts) > contentRootIdx {
// use top level contentRoot ('id' from /ipfs/id or /ipns/id) as affinity key
return parts[contentRootIdx]
}
*/
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lidel lidel merged commit be08e60 into main Feb 24, 2023
@lidel lidel deleted the affinity-key-string branch February 24, 2023 15:10
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants