Fix transactions not being committed#60
Conversation
| with self._connection.cursor() as cursor: | ||
| cursor.execute(query, {"session_id": self._session_id}) | ||
| items = [record[0] for record in cursor.fetchall()] | ||
| self._connection.commit() |
There was a problem hiding this comment.
Does a transaction need to be committed here? There's no mutation that's done in get_messages
There was a problem hiding this comment.
Yes, the transaction is still created and never commits, which can block other operations.
See the first code example in the docs.
There conn.close() closes the transaction.
Another option would be to use Autocommit transactions.
There was a problem hiding this comment.
While doing some research I stumbled on this article, which describes some implications of having not committed transactions.
Basically, it avoids VACUUM marking rows as eligible for reuse, as long as the connection is open.
That means, that if someone builds an application that is rarely restarted using this library, it can grow the size of the DB drastically.
I had an issue where I was not able to access the table from a second project. Turns out some transactions were not commited.
This PR fixes this Issue