Fix off-by-one issue in SheetSynchronizer

This doesn't change the end result of a successful run, though this is what a typical flow looks like prior to this fix:

Consider a sheet with 10 data rows (+ 1 header row = 11). A 10-row data set will call worksheet.setRowCount(10), which truncates the last row of the existing sheet. This row will eventually be added again in the last for loop, but if the synchronizer fails mid-sync, this last row will remain dropped. This fix will prevent this last row from being dropped.

This doesn't fix the broader issue of SheetSynchronizer not behaving transactionally -- that's a different can of worms.

See the linked bug for an instance where the synchronizer failed mid-run and dropped a data row as a result.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=136398109
This commit is contained in:
ctingue 2016-10-17 14:44:12 -07:00 committed by Ben McIlwain
parent 361a53a3c9
commit 1f5a8d5542
2 changed files with 6 additions and 6 deletions

View file

@ -71,7 +71,7 @@ class SheetSynchronizer {
URL url = new URL(SPREADSHEET_URL_PREFIX + spreadsheetId);
SpreadsheetEntry spreadsheet = spreadsheetService.getEntry(url, SpreadsheetEntry.class);
WorksheetEntry worksheet = spreadsheet.getWorksheets().get(0);
worksheet.setRowCount(data.size());
worksheet.setRowCount(data.size() + 1); // account for header row
worksheet = worksheet.update();
ListFeed listFeed = spreadsheetService.getFeed(worksheet.getListFeedUrl(), ListFeed.class);
List<ListEntry> entries = listFeed.getEntries();