mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-08 14:43:09 -06:00
Add back some lazy loading caching
This commit is contained in:
parent
0647844636
commit
858cc61f92
|
|
@ -4,61 +4,32 @@ import (
|
||||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type lazyLoadingCacheKey struct {
|
||||||
|
UserID string // the user we're querying on behalf of
|
||||||
|
DeviceID string // the user we're querying on behalf of
|
||||||
|
RoomID string // the room in question
|
||||||
|
TargetUserID string // the user whose membership we're asking about
|
||||||
|
}
|
||||||
|
|
||||||
type LazyLoadCache interface {
|
type LazyLoadCache interface {
|
||||||
StoreLazyLoadedUser(device *userapi.Device, roomID, userID, eventID string)
|
StoreLazyLoadedUser(device *userapi.Device, roomID, userID, eventID string)
|
||||||
IsLazyLoadedUserCached(device *userapi.Device, roomID, userID string) (string, bool)
|
IsLazyLoadedUserCached(device *userapi.Device, roomID, userID string) (string, bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Caches) lazyLoadCacheForUser(device *userapi.Device) (*RistrettoCachePartition[string, any], error) {
|
|
||||||
return nil, nil
|
|
||||||
/*
|
|
||||||
cacheName := fmt.Sprintf("%s/%s", device.UserID, device.ID)
|
|
||||||
userCache, ok := c.LazyLoading.Get(cacheName)
|
|
||||||
if ok && userCache != nil {
|
|
||||||
if cache, ok := userCache.(*InMemoryLRUCachePartition); ok {
|
|
||||||
return cache, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cache, err := NewInMemoryLRUCachePartition(
|
|
||||||
LazyLoadCacheName,
|
|
||||||
LazyLoadCacheMutable,
|
|
||||||
LazyLoadCacheMaxUserEntries,
|
|
||||||
LazyLoadCacheMaxAge,
|
|
||||||
false,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
c.LazyLoading.Set(cacheName, cache)
|
|
||||||
go cacheCleaner(cache)
|
|
||||||
return cache, nil
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c Caches) StoreLazyLoadedUser(device *userapi.Device, roomID, userID, eventID string) {
|
func (c Caches) StoreLazyLoadedUser(device *userapi.Device, roomID, userID, eventID string) {
|
||||||
/*
|
c.LazyLoading.Set(lazyLoadingCacheKey{
|
||||||
cache, err := c.lazyLoadCacheForUser(device)
|
UserID: device.UserID,
|
||||||
if err != nil {
|
DeviceID: device.ID,
|
||||||
return
|
RoomID: roomID,
|
||||||
}
|
TargetUserID: userID,
|
||||||
cacheKey := fmt.Sprintf("%s/%s/%s/%s", device.UserID, device.ID, roomID, userID)
|
}, eventID)
|
||||||
cache.Set(cacheKey, eventID)
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Caches) IsLazyLoadedUserCached(device *userapi.Device, roomID, userID string) (string, bool) {
|
func (c Caches) IsLazyLoadedUserCached(device *userapi.Device, roomID, userID string) (string, bool) {
|
||||||
return "", false
|
return c.LazyLoading.Get(lazyLoadingCacheKey{
|
||||||
/*
|
UserID: device.UserID,
|
||||||
cache, err := c.lazyLoadCacheForUser(device)
|
DeviceID: device.ID,
|
||||||
if err != nil {
|
RoomID: roomID,
|
||||||
return "", false
|
TargetUserID: userID,
|
||||||
}
|
})
|
||||||
|
|
||||||
cacheKey := fmt.Sprintf("%s/%s/%s/%s", device.UserID, device.ID, roomID, userID)
|
|
||||||
val, ok := cache.Get(cacheKey)
|
|
||||||
if !ok {
|
|
||||||
return "", ok
|
|
||||||
}
|
|
||||||
return val.(string), ok
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ type Caches struct {
|
||||||
FederationPDUs Cache[int64, *gomatrixserverlib.HeaderedEvent]
|
FederationPDUs Cache[int64, *gomatrixserverlib.HeaderedEvent]
|
||||||
FederationEDUs Cache[int64, *gomatrixserverlib.EDU]
|
FederationEDUs Cache[int64, *gomatrixserverlib.EDU]
|
||||||
SpaceSummaryRooms Cache[string, gomatrixserverlib.MSC2946SpacesResponse]
|
SpaceSummaryRooms Cache[string, gomatrixserverlib.MSC2946SpacesResponse]
|
||||||
LazyLoading Cache[string, any]
|
LazyLoading Cache[lazyLoadingCacheKey, string]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cache is the interface that an implementation must satisfy.
|
// Cache is the interface that an implementation must satisfy.
|
||||||
|
|
@ -30,7 +30,7 @@ type Cache[K keyable, T any] interface {
|
||||||
|
|
||||||
type keyable interface {
|
type keyable interface {
|
||||||
// from https://github.com/dgraph-io/ristretto/blob/8e850b710d6df0383c375ec6a7beae4ce48fc8d5/z/z.go#L34
|
// from https://github.com/dgraph-io/ristretto/blob/8e850b710d6df0383c375ec6a7beae4ce48fc8d5/z/z.go#L34
|
||||||
uint64 | string | []byte | byte | int | int32 | uint32 | int64
|
uint64 | string | []byte | byte | int | int32 | uint32 | int64 | lazyLoadingCacheKey
|
||||||
}
|
}
|
||||||
|
|
||||||
type costable interface {
|
type costable interface {
|
||||||
|
|
|
||||||
|
|
@ -111,7 +111,7 @@ func NewRistrettoCache(maxCost config.DataUnit, maxAge time.Duration, enableProm
|
||||||
Mutable: true,
|
Mutable: true,
|
||||||
MaxAge: maxAge,
|
MaxAge: maxAge,
|
||||||
},
|
},
|
||||||
LazyLoading: &RistrettoCachePartition[string, any]{ // TODO: type
|
LazyLoading: &RistrettoCachePartition[lazyLoadingCacheKey, string]{
|
||||||
cache: cache,
|
cache: cache,
|
||||||
Prefix: lazyLoadingCache,
|
Prefix: lazyLoadingCache,
|
||||||
Mutable: true,
|
Mutable: true,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue