Skip to content

Commit

Permalink
Merge pull request #6014 from tomachalek/issue-6012_b
Browse files Browse the repository at this point in the history
Fix #6012:
  • Loading branch information
tomachalek authored Sep 7, 2023
2 parents 93e00e6 + 765cff2 commit e060770
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/plugins/mysql_subc_storage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,18 @@ async def create_preflight(self, subc_root_dir, corpname):
await fw.write(struct.pack('<q', 0))
await fw.write(struct.pack('<q', self.preflight_subcorpus_size))
subcname = f'{corpname}-preflight'
# TODO transaction here
async with self._db.cursor() as cursor:
await cursor.execute('START TRANSACTION')
# Due to caching etc. we always have to perform test whether a preflight subc. exists
# (even if a consumer of this method tests it via corp_info.preflight_subcorpus, it may
# not be the most recent information).
await cursor.execute(
f'SELECT id FROM kontext_preflight_subc WHERE corpus_name = %s LIMIT 1', corpname)
row = await cursor.fetchone()
if row:
await cursor.connection.rollback()
return row['id']

await cursor.execute(
f'INSERT INTO {self._bconf.subccorp_table} '
f'(id, user_id, author_id, corpus_name, name, created, size, is_draft, aligned) '
Expand All @@ -177,6 +187,7 @@ async def create_preflight(self, subc_root_dir, corpname):
'VALUES (%s, %s)',
(subc_id.id, corpname)
)
await cursor.connection.commit()
await Sanic.get_app('kontext').dispatch('kontext.internal.reset')
return subc_id.id

Expand Down

0 comments on commit e060770

Please sign in to comment.