pudo / dataset

Easy-to-use data handling for SQL data stores with support for implicit table creation, bulk loading, and transactions.
https://dataset.readthedocs.org/
MIT License
4.76k stars 297 forks source link

_flush_tabbles() called during commit() causing schema reload (reflection) after each transaction #356

Closed flb1982 closed 3 years ago

flb1982 commented 3 years ago

Greetings,

First of all, thank you for developing Dataset! I find it very useful!

I've noticed that in the last versions of Dataset, my scripts were issuing a lot of 'SHOW FULL TABLES FROM "db" ' commands to my MySQL server (basically one per transaction). I've traced the suspect code to:

def commit(self):
        """Commit the current transaction.

        Make all statements executed since the transaction was begun permanent.
        """
        if hasattr(self.local, "tx") and self.local.tx:
            tx = self.local.tx.pop()
            tx.commit()
            self._flush_tables() # <-- this line

By eliminating the call _self._flushtables() the issue disappears and I do not notice any side effects of eliminating it. Looking into _flushtables(), the description says it is used to "Clear the table metadata after transaction rollbacks."_ Which is not the case during a successful commit.

Are my assumptions correct? If not, is there a reason why a schema reload is necessary after each successful transaction?

Thanks in advance and Happy holidays! Felipe