2021年3月31日星期三

PyMySQL is getting slower each consult at database

I don't know what I'm doing wrong to connect with MySQL database...

class DaoImportantInfo:        def __init__(self, db=None):          self.db = db          self.config = ConfigConnection()          self.tabelas = TabelasConfig()        def getAll(self):          self.db.connect()          cursor = self.db.cursor()            strComando = f"""SELECT tetosPrevId, dataValidade, valor FROM {self.tabelas.tblTetosPrev} ORDER BY dataValidade DESC"""            try:              cursor.execute(strComando)              logPrioridade(f'SELECT<getAllTetos>____________{self.tabelas.tblTetosPrev};', TipoEdicao.select, Prioridade.saidaComun)              return cursor.fetchall()          except:              raise Warning(f'Erro SQL - getAllTetos({self.config.banco}) <INSERT {self.tabelas.tblTetosPrev}>')          finally:              self.disconectBD(cursor)          def disconectBD(self, cursor):          cursor.close()          self.db.close()      

I have a DaoImportantInfo class, who has the connection and some configuration properties, a method getAll who returns all info in tblTetosPrev table and disconnectBD that shold turn off the connection.

The weird situation is that every time I call getAll it takes more time to fetch all the data. The first time it takes less than one second, then, in second time, it takes 2 seconds, then 19 seconds...

I read that is important to close the connection after execute a script, so I don't know what is the problem. Can anybody help me?

I'm using Python 3.8 and Linux PopOs.

https://stackoverflow.com/questions/66897464/pymysql-is-getting-slower-each-consult-at-database April 01, 2021 at 09:52AM

没有评论:

发表评论