(repo repository.ClockedRepo, resolvers func() entity.Resolvers, getUserIdentity getUserIdentityFunc)
| 13 | } |
| 14 | |
| 15 | func NewRepoCacheIdentity(repo repository.ClockedRepo, |
| 16 | resolvers func() entity.Resolvers, |
| 17 | getUserIdentity getUserIdentityFunc) *RepoCacheIdentity { |
| 18 | |
| 19 | makeCached := func(i *identity.Identity, entityUpdated func(id entity.Id) error) *IdentityCache { |
| 20 | return NewIdentityCache(i, repo, entityUpdated) |
| 21 | } |
| 22 | |
| 23 | makeIndex := func(i *IdentityCache) []string { |
| 24 | // no indexing |
| 25 | return nil |
| 26 | } |
| 27 | |
| 28 | // TODO: this is terribly ugly, but we are currently stuck with the fact that identities are NOT using the fancy dag framework. |
| 29 | // This lead to various complication here and there to handle entities generically, and avoid large code duplication. |
| 30 | // TL;DR: something has to give, and this is the less ugly solution I found. This "normalize" identities as just another "dag framework" |
| 31 | // entity. Ideally identities would be converted to the dag framework, but right now that could lead to potential attack: if an old |
| 32 | // private key is leaked, it would be possible to craft a legal identity update that take over the most recent version. While this is |
| 33 | // meaningless in the case of a normal entity, it's really an issues for identities. |
| 34 | |
| 35 | actions := Actions[*identity.Identity]{ |
| 36 | ReadWithResolver: func(repo repository.ClockedRepo, resolvers entity.Resolvers, id entity.Id) (*identity.Identity, error) { |
| 37 | return identity.ReadLocal(repo, id) |
| 38 | }, |
| 39 | ReadAllWithResolver: func(repo repository.ClockedRepo, resolvers entity.Resolvers) <-chan entity.StreamedEntity[*identity.Identity] { |
| 40 | return identity.ReadAllLocal(repo) |
| 41 | }, |
| 42 | Remove: identity.Remove, |
| 43 | RemoveAll: identity.RemoveAll, |
| 44 | MergeAll: func(repo repository.ClockedRepo, resolvers entity.Resolvers, remote string, mergeAuthor identity.Interface) <-chan entity.MergeResult { |
| 45 | return identity.MergeAll(repo, remote) |
| 46 | }, |
| 47 | } |
| 48 | |
| 49 | sc := NewSubCache[*identity.Identity, *IdentityExcerpt, *IdentityCache]( |
| 50 | repo, resolvers, getUserIdentity, |
| 51 | makeCached, NewIdentityExcerpt, makeIndex, actions, |
| 52 | identity.Typename, identity.Namespace, |
| 53 | formatVersion, defaultMaxLoadedBugs, |
| 54 | ) |
| 55 | |
| 56 | return &RepoCacheIdentity{SubCache: sc} |
| 57 | } |
| 58 | |
| 59 | // ResolveIdentityImmutableMetadata retrieve an Identity that has the exact given metadata on |
| 60 | // one of its version. If multiple version have the same key, the first defined take precedence. |
no test coverage detected