Add an LRU cache to the config.
This commit is contained in:
parent
d2b744b195
commit
68ef9b97a3
@ -27,6 +27,7 @@ we borrow some methods and classes from there where it makes sense.
|
|||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
import textwrap
|
import textwrap
|
||||||
|
import functools
|
||||||
import configparser
|
import configparser
|
||||||
import collections.abc
|
import collections.abc
|
||||||
|
|
||||||
@ -277,6 +278,7 @@ class ConfigManager(QObject):
|
|||||||
existed = optname in sectdict
|
existed = optname in sectdict
|
||||||
if existed:
|
if existed:
|
||||||
del sectdict[optname]
|
del sectdict[optname]
|
||||||
|
self.get.cache_clear()
|
||||||
return existed
|
return existed
|
||||||
|
|
||||||
@cmdutils.register(name='get', instance='config',
|
@cmdutils.register(name='get', instance='config',
|
||||||
@ -301,6 +303,7 @@ class ConfigManager(QObject):
|
|||||||
message.info("{} {} = {}".format(sectname, optname, val),
|
message.info("{} {} = {}".format(sectname, optname, val),
|
||||||
immediately=True)
|
immediately=True)
|
||||||
|
|
||||||
|
@functools.lru_cache()
|
||||||
def get(self, sectname, optname, raw=False, transformed=True):
|
def get(self, sectname, optname, raw=False, transformed=True):
|
||||||
"""Get the value from a section/option.
|
"""Get the value from a section/option.
|
||||||
|
|
||||||
@ -411,6 +414,7 @@ class ConfigManager(QObject):
|
|||||||
if sectname in ('colors', 'fonts'):
|
if sectname in ('colors', 'fonts'):
|
||||||
self.style_changed.emit(sectname, optname)
|
self.style_changed.emit(sectname, optname)
|
||||||
self.changed.emit(sectname, optname)
|
self.changed.emit(sectname, optname)
|
||||||
|
self.get.cache_clear()
|
||||||
|
|
||||||
@cmdutils.register(instance='config')
|
@cmdutils.register(instance='config')
|
||||||
def save(self):
|
def save(self):
|
||||||
|
@ -29,6 +29,7 @@ from PyQt5.QtCore import pyqtRemoveInputHook, QEvent, QCoreApplication
|
|||||||
|
|
||||||
from qutebrowser.utils import log, utils
|
from qutebrowser.utils import log, utils
|
||||||
from qutebrowser.commands import cmdutils
|
from qutebrowser.commands import cmdutils
|
||||||
|
from qutebrowser.config import config
|
||||||
|
|
||||||
|
|
||||||
@cmdutils.register(debug=True, name='debug-set-trace')
|
@cmdutils.register(debug=True, name='debug-set-trace')
|
||||||
@ -83,6 +84,11 @@ def debug_all_objects():
|
|||||||
s = QCoreApplication.instance().get_all_objects()
|
s = QCoreApplication.instance().get_all_objects()
|
||||||
log.misc.debug(s)
|
log.misc.debug(s)
|
||||||
|
|
||||||
|
@cmdutils.register(debug=True)
|
||||||
|
def debug_cache_stats():
|
||||||
|
"""Print config LRU cache stats."""
|
||||||
|
info = config.instance().get.cache_info()
|
||||||
|
log.misc.debug(info)
|
||||||
|
|
||||||
def log_events(klass):
|
def log_events(klass):
|
||||||
"""Class decorator to log Qt events."""
|
"""Class decorator to log Qt events."""
|
||||||
|
Loading…
Reference in New Issue
Block a user