sheetsync: Only allocate ids when first needed

This prevents rate limiting issues when immediately allocating all 999 ids
for an empty sheet.
pull/54/head
Mike Lang 6 years ago
parent 11fc67f071
commit f354130434

@ -106,18 +106,6 @@ class SheetSync(object):
if row_index == 0: if row_index == 0:
continue continue
row = self.parse_row(row) row = self.parse_row(row)
if row['id'] is None:
if self.allocate_ids:
row['id'] = uuid.uuid4()
logging.info("Allocating id for row {!r}:{} = {}".format(worksheet, row_index, row['id']))
self.sheets.write_value(
self.sheet_id, worksheet,
row_index, self.column_map['id'],
str(row['id']),
)
else:
logging.warning("Row {!r}:{} has no valid id, skipping".format(worksheet, row_index))
continue
self.sync_row(worksheet, row_index, row, events.get(row['id'])) self.sync_row(worksheet, row_index, row, events.get(row['id']))
except Exception: except Exception:
logging.exception("Failed to sync") logging.exception("Failed to sync")
@ -160,6 +148,22 @@ class SheetSync(object):
# Otherwise ignore it. # Otherwise ignore it.
if not any(row[col] for col in self.input_columns): if not any(row[col] for col in self.input_columns):
return return
# Only generate row when needed (unless it's already there)
# Originally we would allocate rows on first sync, but this led to rate limiting issues.
if row['id'] is None:
if self.allocate_ids:
row['id'] = uuid.uuid4()
logging.info("Allocating id for row {!r}:{} = {}".format(worksheet, row_index, row['id']))
self.sheets.write_value(
self.sheet_id, worksheet,
row_index, self.column_map['id'],
str(row['id']),
)
else:
logging.warning("Row {!r}:{} has no valid id, skipping".format(worksheet, row_index))
return
logging.info("Inserting new event {}".format(row['id'])) logging.info("Inserting new event {}".format(row['id']))
# Insertion conflict just means that another sheet sync beat us to the insert. # Insertion conflict just means that another sheet sync beat us to the insert.
# We can ignore it. # We can ignore it.

Loading…
Cancel
Save