@@ -66,7 +66,7 @@ class Storage:
66
66
def __init__ (self ) -> None :
67
67
self ._general = Storage ._create_persistent_dict ('general' )
68
68
self ._users : Dict [str , PersistentDict ] = {}
69
- self ._tabs : Dict [str , PersistentDict ] = {}
69
+ self ._tabs : Dict [str , ObservableDict ] = {}
70
70
71
71
@staticmethod
72
72
def _create_persistent_dict (id : str ) -> PersistentDict : # pylint: disable=redefined-builtin
@@ -163,13 +163,21 @@ def tab(self) -> observables.ObservableDict:
163
163
async def _create_tab_storage (self , tab_id : str ) -> None :
164
164
"""Create tab storage for the given tab ID."""
165
165
if tab_id not in self ._tabs :
166
- self ._tabs [tab_id ] = Storage ._create_persistent_dict (f'tab-{ tab_id } ' )
167
- await self ._tabs [tab_id ].initialize ()
166
+ if Storage .redis_url :
167
+ self ._tabs [tab_id ] = Storage ._create_persistent_dict (f'tab-{ tab_id } ' )
168
+ tab = self ._tabs [tab_id ]
169
+ assert isinstance (tab , PersistentDict )
170
+ await tab .initialize ()
171
+ else :
172
+ self ._tabs [tab_id ] = ObservableDict ()
168
173
169
174
def copy_tab (self , old_tab_id : str , tab_id : str ) -> None :
170
175
"""Copy the tab storage to a new tab. (For internal use only.)"""
171
176
if old_tab_id in self ._tabs :
172
- self ._tabs [tab_id ] = Storage ._create_persistent_dict (f'tab-{ tab_id } ' )
177
+ if Storage .redis_url :
178
+ self ._tabs [tab_id ] = Storage ._create_persistent_dict (f'tab-{ tab_id } ' )
179
+ else :
180
+ self ._tabs [tab_id ] = ObservableDict ()
173
181
self ._tabs [tab_id ].update (self ._tabs [old_tab_id ])
174
182
175
183
async def prune_tab_storage (self ) -> None :
@@ -178,7 +186,8 @@ async def prune_tab_storage(self) -> None:
178
186
for tab_id , tab in list (self ._tabs .items ()):
179
187
if time .time () > tab .last_modified + self .max_tab_storage_age :
180
188
tab .clear ()
181
- await tab .close ()
189
+ if isinstance (tab , PersistentDict ):
190
+ await tab .close ()
182
191
del self ._tabs [tab_id ]
183
192
await asyncio .sleep (PURGE_INTERVAL )
184
193
0 commit comments