rtutil: Add debug logging to RTLinkCache.setup.
To help with RT#10543.
This commit is contained in:
parent
30e386f645
commit
079d8ec9a3
1 changed files with 10 additions and 0 deletions
|
@ -15,6 +15,7 @@
|
|||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import functools
|
||||
import logging
|
||||
import mimetypes
|
||||
import os
|
||||
import re
|
||||
|
@ -78,6 +79,7 @@ class RTLinkCache(_LinkCache):
|
|||
url TEXT NOT NULL,
|
||||
PRIMARY KEY (ticket_id, attachment_id)
|
||||
)"""
|
||||
logger = logging.getLogger('conservancy_beancount.rtutil.RTLinkCache')
|
||||
|
||||
@classmethod
|
||||
def setup(cls, cache_path: Path) -> Optional[sqlite3.Connection]:
|
||||
|
@ -89,6 +91,7 @@ class RTLinkCache(_LinkCache):
|
|||
have_data = cursor.fetchone() is not None
|
||||
except sqlite3.OperationalError:
|
||||
# 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
|
||||
try:
|
||||
# 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.
|
||||
cursor.execute('DELETE FROM RTLinkCache WHERE url IS NULL')
|
||||
except sqlite3.OperationalError:
|
||||
cls.logger.debug("setup: error writing %s", cache_path, exc_info=True)
|
||||
can_write = False
|
||||
else:
|
||||
can_write = True
|
||||
if not (can_write or have_data):
|
||||
# If there's nothing to read and no way to write, sqlite provides
|
||||
# no benefit.
|
||||
cls.logger.debug("setup: not using %s: nothing to read or write", cache_path)
|
||||
return None
|
||||
elif not can_write:
|
||||
# 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:
|
||||
# We're back to the case of having nothing to read and no way
|
||||
# to write.
|
||||
cls.logger.debug("setup: error loading %s into memory", cache_path, exc_info=True)
|
||||
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()
|
||||
db.commit()
|
||||
return db
|
||||
|
|
Loading…
Reference in a new issue