使用SQLAlchemy改进性能

2024-10-01 00:14:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图使用SQLAlchemy构建一个bitemporal model,但遇到了性能问题。你知道吗

def update(new_record)
    if new_record does not exist in db then
       1) update existing old record with same primary key as new_record by setting validTo date as today and I am using SQLAlchemy's merge here.
       2) insert new record with new validFrom and validTo dates using SQLAlchemy's add() 

如果我叫这个update大约10次,然后做commit,需要20-25秒,这是很多。我错过了什么?在SQLAlchemy中执行合并/添加循环是不好的,如何解决这个问题?你知道吗


Tags: andnewmodelifsqlalchemydefaswith