mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Fix for race condition in refresh_schemas(), closes #1231
This commit is contained in:
parent
dd5ee8e668
commit
c00f29affc
2 changed files with 12 additions and 5 deletions
|
|
@ -224,6 +224,7 @@ class Datasette:
|
|||
self.inspect_data = inspect_data
|
||||
self.immutables = set(immutables or [])
|
||||
self.databases = collections.OrderedDict()
|
||||
self._refresh_schemas_lock = asyncio.Lock()
|
||||
self.crossdb = crossdb
|
||||
if memory or crossdb or not self.files:
|
||||
self.add_database(Database(self, is_memory=True), name="_memory")
|
||||
|
|
@ -332,6 +333,12 @@ class Datasette:
|
|||
self.client = DatasetteClient(self)
|
||||
|
||||
async def refresh_schemas(self):
|
||||
if self._refresh_schemas_lock.locked():
|
||||
return
|
||||
async with self._refresh_schemas_lock:
|
||||
await self._refresh_schemas()
|
||||
|
||||
async def _refresh_schemas(self):
|
||||
internal_db = self.databases["_internal"]
|
||||
if not self.internal_db_created:
|
||||
await init_internal_db(internal_db)
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ async def init_internal_db(db):
|
|||
await db.execute_write(
|
||||
textwrap.dedent(
|
||||
"""
|
||||
CREATE TABLE databases (
|
||||
CREATE TABLE IF NOT EXISTS databases (
|
||||
database_name TEXT PRIMARY KEY,
|
||||
path TEXT,
|
||||
is_memory INTEGER,
|
||||
|
|
@ -18,7 +18,7 @@ async def init_internal_db(db):
|
|||
await db.execute_write(
|
||||
textwrap.dedent(
|
||||
"""
|
||||
CREATE TABLE tables (
|
||||
CREATE TABLE IF NOT EXISTS tables (
|
||||
database_name TEXT,
|
||||
table_name TEXT,
|
||||
rootpage INTEGER,
|
||||
|
|
@ -33,7 +33,7 @@ async def init_internal_db(db):
|
|||
await db.execute_write(
|
||||
textwrap.dedent(
|
||||
"""
|
||||
CREATE TABLE columns (
|
||||
CREATE TABLE IF NOT EXISTS columns (
|
||||
database_name TEXT,
|
||||
table_name TEXT,
|
||||
cid INTEGER,
|
||||
|
|
@ -54,7 +54,7 @@ async def init_internal_db(db):
|
|||
await db.execute_write(
|
||||
textwrap.dedent(
|
||||
"""
|
||||
CREATE TABLE indexes (
|
||||
CREATE TABLE IF NOT EXISTS indexes (
|
||||
database_name TEXT,
|
||||
table_name TEXT,
|
||||
seq INTEGER,
|
||||
|
|
@ -73,7 +73,7 @@ async def init_internal_db(db):
|
|||
await db.execute_write(
|
||||
textwrap.dedent(
|
||||
"""
|
||||
CREATE TABLE foreign_keys (
|
||||
CREATE TABLE IF NOT EXISTS foreign_keys (
|
||||
database_name TEXT,
|
||||
table_name TEXT,
|
||||
id INTEGER,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue