Skip to content

Commit

Permalink
fixup! [IMP] snippets: move all work from parent to mp workers
Browse files Browse the repository at this point in the history
  • Loading branch information
cawo-odoo committed Nov 14, 2024
1 parent fe9b2c8 commit 3a916ac
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/util/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,17 +248,22 @@ def _dumps(self, node):


class Convertor:
def __init__(self, converters, callback, dbname, update_query):
def __init__(self, converters, callback, dbname=None, update_query=None):
self.converters = converters
self.callback = callback
self.dbname = dbname
self.update_query = update_query

def __call__(self, query):
# backwards compatibility
if not (self.dbname and self.update_query and isinstance(query, str)):
return self._convert_row(query)
# called with a query to fetch a number of rows
with db_connect(self.dbname).cursor() as cr:
cr.execute(query)
for changes in filter(None, map(self._convert_row, cr.fetchall())):
cr.execute(self.update_query, changes)
return None

def _convert_row(self, row):
converters = self.converters
Expand Down

0 comments on commit 3a916ac

Please sign in to comment.