aboutsummaryrefslogtreecommitdiff
path: root/internal/caching
diff options
context:
space:
mode:
authorNeil Alexander <neilalexander@users.noreply.github.com>2022-02-18 10:58:41 +0000
committerGitHub <noreply@github.com>2022-02-18 10:58:41 +0000
commit131bedc1a11135eb1f67a26389fe8f53c82c537d (patch)
tree1c66c0fde3098629948198c1d7262e559fd24921 /internal/caching
parente1eb5807b66940490291983be905f2849539aa7f (diff)
Remove event type and state key caches (#2200)
* Don't proactively cache event types and state keys when we don't know if the transaction has persisted yet * Remove event type and state key caches altogether
Diffstat (limited to 'internal/caching')
-rw-r--r--internal/caching/cache_roomservernids.go42
-rw-r--r--internal/caching/caches.go14
-rw-r--r--internal/caching/impl_inmemorylru.go33
3 files changed, 12 insertions, 77 deletions
diff --git a/internal/caching/cache_roomservernids.go b/internal/caching/cache_roomservernids.go
index bf4fe85e..6d413093 100644
--- a/internal/caching/cache_roomservernids.go
+++ b/internal/caching/cache_roomservernids.go
@@ -7,14 +7,6 @@ import (
)
const (
- RoomServerStateKeyNIDsCacheName = "roomserver_statekey_nids"
- RoomServerStateKeyNIDsCacheMaxEntries = 1024
- RoomServerStateKeyNIDsCacheMutable = false
-
- RoomServerEventTypeNIDsCacheName = "roomserver_eventtype_nids"
- RoomServerEventTypeNIDsCacheMaxEntries = 64
- RoomServerEventTypeNIDsCacheMutable = false
-
RoomServerRoomIDsCacheName = "roomserver_room_ids"
RoomServerRoomIDsCacheMaxEntries = 1024
RoomServerRoomIDsCacheMutable = false
@@ -29,44 +21,10 @@ type RoomServerCaches interface {
// RoomServerNIDsCache contains the subset of functions needed for
// a roomserver NID cache.
type RoomServerNIDsCache interface {
- GetRoomServerStateKeyNID(stateKey string) (types.EventStateKeyNID, bool)
- StoreRoomServerStateKeyNID(stateKey string, nid types.EventStateKeyNID)
-
- GetRoomServerEventTypeNID(eventType string) (types.EventTypeNID, bool)
- StoreRoomServerEventTypeNID(eventType string, nid types.EventTypeNID)
-
GetRoomServerRoomID(roomNID types.RoomNID) (string, bool)
StoreRoomServerRoomID(roomNID types.RoomNID, roomID string)
}
-func (c Caches) GetRoomServerStateKeyNID(stateKey string) (types.EventStateKeyNID, bool) {
- val, found := c.RoomServerStateKeyNIDs.Get(stateKey)
- if found && val != nil {
- if stateKeyNID, ok := val.(types.EventStateKeyNID); ok {
- return stateKeyNID, true
- }
- }
- return 0, false
-}
-
-func (c Caches) StoreRoomServerStateKeyNID(stateKey string, nid types.EventStateKeyNID) {
- c.RoomServerStateKeyNIDs.Set(stateKey, nid)
-}
-
-func (c Caches) GetRoomServerEventTypeNID(eventType string) (types.EventTypeNID, bool) {
- val, found := c.RoomServerEventTypeNIDs.Get(eventType)
- if found && val != nil {
- if eventTypeNID, ok := val.(types.EventTypeNID); ok {
- return eventTypeNID, true
- }
- }
- return 0, false
-}
-
-func (c Caches) StoreRoomServerEventTypeNID(eventType string, nid types.EventTypeNID) {
- c.RoomServerEventTypeNIDs.Set(eventType, nid)
-}
-
func (c Caches) GetRoomServerRoomID(roomNID types.RoomNID) (string, bool) {
val, found := c.RoomServerRoomIDs.Get(strconv.Itoa(int(roomNID)))
if found && val != nil {
diff --git a/internal/caching/caches.go b/internal/caching/caches.go
index f04d05d4..e1642a66 100644
--- a/internal/caching/caches.go
+++ b/internal/caching/caches.go
@@ -4,14 +4,12 @@ package caching
// different implementations as long as they satisfy the Cache
// interface.
type Caches struct {
- RoomVersions Cache // RoomVersionCache
- ServerKeys Cache // ServerKeyCache
- RoomServerStateKeyNIDs Cache // RoomServerNIDsCache
- RoomServerEventTypeNIDs Cache // RoomServerNIDsCache
- RoomServerRoomNIDs Cache // RoomServerNIDsCache
- RoomServerRoomIDs Cache // RoomServerNIDsCache
- RoomInfos Cache // RoomInfoCache
- FederationEvents Cache // FederationEventsCache
+ RoomVersions Cache // RoomVersionCache
+ ServerKeys Cache // ServerKeyCache
+ RoomServerRoomNIDs Cache // RoomServerNIDsCache
+ RoomServerRoomIDs Cache // RoomServerNIDsCache
+ RoomInfos Cache // RoomInfoCache
+ FederationEvents Cache // FederationEventsCache
}
// Cache is the interface that an implementation must satisfy.
diff --git a/internal/caching/impl_inmemorylru.go b/internal/caching/impl_inmemorylru.go
index f0915d7c..ccb92852 100644
--- a/internal/caching/impl_inmemorylru.go
+++ b/internal/caching/impl_inmemorylru.go
@@ -28,24 +28,6 @@ func NewInMemoryLRUCache(enablePrometheus bool) (*Caches, error) {
if err != nil {
return nil, err
}
- roomServerStateKeyNIDs, err := NewInMemoryLRUCachePartition(
- RoomServerStateKeyNIDsCacheName,
- RoomServerStateKeyNIDsCacheMutable,
- RoomServerStateKeyNIDsCacheMaxEntries,
- enablePrometheus,
- )
- if err != nil {
- return nil, err
- }
- roomServerEventTypeNIDs, err := NewInMemoryLRUCachePartition(
- RoomServerEventTypeNIDsCacheName,
- RoomServerEventTypeNIDsCacheMutable,
- RoomServerEventTypeNIDsCacheMaxEntries,
- enablePrometheus,
- )
- if err != nil {
- return nil, err
- }
roomServerRoomIDs, err := NewInMemoryLRUCachePartition(
RoomServerRoomIDsCacheName,
RoomServerRoomIDsCacheMutable,
@@ -74,18 +56,15 @@ func NewInMemoryLRUCache(enablePrometheus bool) (*Caches, error) {
return nil, err
}
go cacheCleaner(
- roomVersions, serverKeys, roomServerStateKeyNIDs,
- roomServerEventTypeNIDs, roomServerRoomIDs,
+ roomVersions, serverKeys, roomServerRoomIDs,
roomInfos, federationEvents,
)
return &Caches{
- RoomVersions: roomVersions,
- ServerKeys: serverKeys,
- RoomServerStateKeyNIDs: roomServerStateKeyNIDs,
- RoomServerEventTypeNIDs: roomServerEventTypeNIDs,
- RoomServerRoomIDs: roomServerRoomIDs,
- RoomInfos: roomInfos,
- FederationEvents: federationEvents,
+ RoomVersions: roomVersions,
+ ServerKeys: serverKeys,
+ RoomServerRoomIDs: roomServerRoomIDs,
+ RoomInfos: roomInfos,
+ FederationEvents: federationEvents,
}, nil
}