Skip to content

Commit

Permalink
optimize db creation (#14231)
Browse files Browse the repository at this point in the history
  • Loading branch information
memsharded authored Jul 6, 2023
1 parent 57c7049 commit ebee60f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 5 additions & 0 deletions conan/internal/cache/db/cache_database.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

from conan.internal.cache.db.packages_table import PackagesDBTable
from conan.internal.cache.db.recipes_table import RecipesDBTable
from conans.model.package_ref import PkgReference
Expand All @@ -11,6 +13,9 @@ class CacheDatabase:
def __init__(self, filename):
self._recipes = RecipesDBTable(filename)
self._packages = PackagesDBTable(filename)
if not os.path.isfile(filename):
self._recipes.create_table()
self._packages.create_table()

def exists_prev(self, ref):
# TODO: This logic could be done directly against DB
Expand Down
5 changes: 2 additions & 3 deletions conan/internal/cache/db/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ def __init__(self, filename):
column_names: List[str] = [it[0] for it in self.columns_description]
self.row_type = namedtuple('_', column_names)
self.columns = self.row_type(*column_names)
self.create_table()

@contextmanager
def db_connection(self):
connection = sqlite3.connect(self.filename, isolation_level=None,
timeout=1, check_same_thread=False)
try:
connection = sqlite3.connect(self.filename, isolation_level=None,
timeout=1, check_same_thread=False)
yield connection
finally:
connection.close()
Expand Down

0 comments on commit ebee60f

Please sign in to comment.