Skip to content

Commit

Permalink
Get latest tid on database with MAX(tid) instead of checking sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
vangheem committed May 12, 2017
1 parent d400912 commit 0a7e276
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.rst
@@ -1,7 +1,8 @@
1.0.0a24 (unreleased)
---------------------

- Nothing changed yet.
- Get latest tid on database with MAX(tid) instead of checking sequence
[vangheem]


1.0.0a23 (2017-05-11)
Expand Down
8 changes: 6 additions & 2 deletions guillotina/db/storages/pg.py
Expand Up @@ -100,7 +100,7 @@


NEXT_TID = "SELECT nextval('tid_sequence');"
MAX_TID = "SELECT last_value FROM tid_sequence;"
MAX_TID = "SELECT MAX(tid) FROM objects;"


NUM_CHILDREN = "SELECT count(*) FROM objects WHERE parent_id = $1::varchar(32)"
Expand Down Expand Up @@ -348,7 +348,11 @@ async def get_next_tid(self, txn):
async def get_current_tid(self, txn):
async with self._lock:
# again, use storage lock here instead of trns lock
return await self._stmt_max_tid.fetchval()
result = await self._stmt_max_tid.fetchval()
if result is None:
# very first transaction won't have a value here...
return 0
return result

async def start_transaction(self, txn):
txn._db_txn = txn._db_conn.transaction(readonly=self._read_only)
Expand Down

0 comments on commit 0a7e276

Please sign in to comment.