[tor-commits] [stem/master] Stub sqlite support for manual caches

atagar at torproject.org atagar at torproject.org
Fri Aug 25 20:32:14 UTC 2017


commit 4cfc014f8730c148511b5407a37d2e50ba07f01e
Author: Damian Johnson <atagar at torproject.org>
Date:   Wed Aug 23 10:53:22 2017 -0700

    Stub sqlite support for manual caches
    
    Stem's Config class is handy when we need human-editable configuratoins but
    when it comes to our auto-generated caches (manual information and fallback
    directories) better to use sqlite. Curious to see what kind of performance this
    gets us, and for nyx it might improve memory usage too. We'll see.
---
 stem/manual.py | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/stem/manual.py b/stem/manual.py
index 9287033e..66e0abf3 100644
--- a/stem/manual.py
+++ b/stem/manual.py
@@ -49,6 +49,7 @@ us what our torrc options do...
 
 import os
 import shutil
+import sqlite3
 import sys
 import tempfile
 
@@ -312,6 +313,10 @@ class Manual(object):
     requirements, and is faster too. Only drawback is that this manual
     content is only as up to date as the Stem release we're using.
 
+    .. versionchanged:: 1.6.0
+       Added support for sqlite cache. Support for
+       :class:`~stem.util.conf.Config` caches will be dropped in Stem 2.x.
+
     :param str path: cached manual content to read, if not provided this uses
       the bundled manual information
 
@@ -320,6 +325,19 @@ class Manual(object):
     :raises: **IOError** if a **path** was provided and we were unable to read it
     """
 
+    # TODO: drop _from_config_cache() with stem 2.x
+
+    if path is not None and path.endswith('.sqlite'):
+      return Manual._from_sqlite_cache(path)
+    else:
+      return Manual._from_config_cache(path)
+
+  @staticmethod
+  def _from_sqlite_cache(path):
+    pass
+
+  @staticmethod
+  def _from_config_cache(path):
     conf = stem.util.conf.Config()
     conf.load(path if path else CACHE_PATH, commenting = False)
 
@@ -434,11 +452,26 @@ class Manual(object):
     """
     Persists the manual content to a given location.
 
+    .. versionchanged:: 1.6.0
+       Added support for sqlite cache. Support for
+       :class:`~stem.util.conf.Config` caches will be dropped in Stem 2.x.
+
     :param str path: path to save our manual content to
 
     :raises: **IOError** if unsuccessful
     """
 
+    # TODO: drop _save_as_config() with stem 2.x
+
+    if path.endswith('.sqlite'):
+      return self._save_as_sqlite(path)
+    else:
+      return self._save_as_config(path)
+
+  def _save_as_sqlite(self, path):
+    pass
+
+  def _save_as_config(self, path):
     conf = stem.util.conf.Config()
     conf.set('name', self.name)
     conf.set('synopsis', self.synopsis)





More information about the tor-commits mailing list