From f668faa8940ba02e796e016ff27f2e4620b49a29 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sun, 19 Apr 2020 15:57:49 +0300 Subject: Process different rooms in sync responses in goroutines --- matrix/rooms/room.go | 7 ------- matrix/rooms/roomcache.go | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 7 deletions(-) (limited to 'matrix/rooms') diff --git a/matrix/rooms/room.go b/matrix/rooms/room.go index 87e63f0..df7160c 100644 --- a/matrix/rooms/room.go +++ b/matrix/rooms/room.go @@ -213,13 +213,6 @@ func (room *Room) Unload() bool { debug.Print("Unloading", room.ID) room.Save() room.state = nil - room.topicCache = "" - room.CanonicalAliasCache = "" - room.firstMemberCache = nil - room.secondMemberCache = nil - room.memberCache = nil - room.exMemberCache = nil - room.replacedByCache = nil if room.postUnload != nil { room.postUnload() } diff --git a/matrix/rooms/roomcache.go b/matrix/rooms/roomcache.go index d442734..9da1922 100644 --- a/matrix/rooms/roomcache.go +++ b/matrix/rooms/roomcache.go @@ -39,6 +39,7 @@ type RoomCache struct { maxSize int maxAge int64 getOwner func() id.UserID + noUnload bool Map map[id.RoomID]*Room head *Room @@ -58,6 +59,14 @@ func NewRoomCache(listPath, directory string, maxSize int, maxAge int64, getOwne } } +func (cache *RoomCache) DisableUnloading() { + cache.noUnload = true +} + +func (cache *RoomCache) EnableUnloading() { + cache.noUnload = false +} + func (cache *RoomCache) LoadList() error { cache.Lock() defer cache.Unlock() @@ -160,6 +169,9 @@ func (cache *RoomCache) Touch(roomID id.RoomID) { } func (cache *RoomCache) TouchNode(node *Room) { + if cache.noUnload || node.touch + 2 > time.Now().Unix() { + return + } cache.Lock() cache.touch(node) cache.Unlock() @@ -200,6 +212,7 @@ func (cache *RoomCache) get(roomID id.RoomID) *Room { } return nil } + func (cache *RoomCache) Put(room *Room) { cache.Lock() node := cache.get(room.ID) @@ -283,6 +296,9 @@ func (cache *RoomCache) ForceClean() { } func (cache *RoomCache) clean(force bool) { + if cache.noUnload && !force { + return + } origSize := cache.size maxTS := time.Now().Unix() - cache.maxAge for cache.size > cache.maxSize { -- cgit v1.2.3