rtutil: Add debug logging to RTLinkCache.setup.

To help with RT#10543.
This commit is contained in:
Brett Smith 2020-05-13 10:12:59 -04:00
parent 30e386f645
commit 079d8ec9a3

View file

@ -15,6 +15,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
import functools import functools
import logging
import mimetypes import mimetypes
import os import os
import re import re
@ -78,6 +79,7 @@ class RTLinkCache(_LinkCache):
url TEXT NOT NULL, url TEXT NOT NULL,
PRIMARY KEY (ticket_id, attachment_id) PRIMARY KEY (ticket_id, attachment_id)
)""" )"""
logger = logging.getLogger('conservancy_beancount.rtutil.RTLinkCache')
@classmethod @classmethod
def setup(cls, cache_path: Path) -> Optional[sqlite3.Connection]: def setup(cls, cache_path: Path) -> Optional[sqlite3.Connection]:
@ -89,6 +91,7 @@ class RTLinkCache(_LinkCache):
have_data = cursor.fetchone() is not None have_data = cursor.fetchone() is not None
except sqlite3.OperationalError: except sqlite3.OperationalError:
# If we couldn't get this far, sqlite provides no benefit. # If we couldn't get this far, sqlite provides no benefit.
cls.logger.debug("setup: error loading %s", cache_path, exc_info=True)
return None return None
try: try:
# There shouldn't be any records where url is NULL, so running this # There shouldn't be any records where url is NULL, so running this
@ -96,12 +99,14 @@ class RTLinkCache(_LinkCache):
# can write to the database and it enforces database integrity. # can write to the database and it enforces database integrity.
cursor.execute('DELETE FROM RTLinkCache WHERE url IS NULL') cursor.execute('DELETE FROM RTLinkCache WHERE url IS NULL')
except sqlite3.OperationalError: except sqlite3.OperationalError:
cls.logger.debug("setup: error writing %s", cache_path, exc_info=True)
can_write = False can_write = False
else: else:
can_write = True can_write = True
if not (can_write or have_data): if not (can_write or have_data):
# If there's nothing to read and no way to write, sqlite provides # If there's nothing to read and no way to write, sqlite provides
# no benefit. # no benefit.
cls.logger.debug("setup: not using %s: nothing to read or write", cache_path)
return None return None
elif not can_write: elif not can_write:
# Set up an in-memory database that we can write to, seeded with # Set up an in-memory database that we can write to, seeded with
@ -119,7 +124,12 @@ class RTLinkCache(_LinkCache):
except sqlite3.OperationalError as error: except sqlite3.OperationalError as error:
# We're back to the case of having nothing to read and no way # We're back to the case of having nothing to read and no way
# to write. # to write.
cls.logger.debug("setup: error loading %s into memory", cache_path, exc_info=True)
return None return None
else:
cls.logger.debug("setup: loaded %s into memory", cache_path)
else:
cls.logger.debug("setup: caching at %s", cache_path)
cursor.close() cursor.close()
db.commit() db.commit()
return db return db