in core/lib/payload/copy.py [0:0]
def divide_changes_to_group(self, chg_rows):
"""
Put consecutive changes with the same type into a group so that we can
execute them in a single query to speed up replay
@param chg_rows: list of rows returned from _chg select query
@type chg_rows: list[dict]
"""
id_group = []
type_now = None
for idx, chg in enumerate(chg_rows):
# Start of the current group
if type_now is None:
type_now = chg[self.DMLCOLNAME]
id_group.append(chg[self.IDCOLNAME])
# Dump when we are at the end of the changes
if idx == len(chg_rows) - 1:
yield type_now, id_group
return
# update type cannot be grouped
elif type_now == self.DML_TYPE_UPDATE:
yield type_now, id_group
type_now = None
id_group = []
# The next change is a different type, dump what we have now
elif chg_rows[idx + 1][self.DMLCOLNAME] != type_now:
yield type_now, id_group
type_now = None
id_group = []
# Reach the max group size, let's submit the query for now
elif len(id_group) >= self.replay_group_size:
yield type_now, id_group
type_now = None
id_group = []
# The next element will be the same as what we are now
else:
continue