我创建了一个Google电子表格,我想将其同步到Google Fusion Tables。最后,我想创建一个仪表板,提供电子表格中的(有些)实时可视信息。 (我希望能够映射业务,业务类别,并为需要访问的企业使用不同的图标)。
目前,我的电子表格有大约570行x~24列,但全年都会添加新行,并且可能会将数据添加到现有单元格中。
我使用了这个:http://fusion-tables-api-samples.googlecode.com/svn/trunk/FusionTablesFormSync/docs/reference.html并确保为apps脚本和开发者控制台启用融合表服务。
我的问题是,在6分钟的时间范围内,只有115行已同步(rowid列中的值)。再次运行同步功能可以添加1-2行。
如何加快处理速度和/或让它从中断处继续进行同步?
编辑: 因此,为了获得尚未添加的行,我注释掉同步函数的一部分,该部分检查电子表格中是否存在该行,如果是,则确保值相同,否则更新。
运行同步功能时,这是执行记录: [14-07-22 14:08:54:798 EDT]开始执行 [14-07-22 14:08:54:856 EDT] ScriptProperties.getProperty([docid])[0.038秒] [14-07-22 14:08:54:872 EDT] ScriptProperties.getProperty([addressColumn])[0.014秒] [14-07-22 14:08:54:889 EDT] ScriptProperties.getProperty([latlngColumn])[0.015秒] [14-07-22 14:08:54:889 EDT] Session.getScriptTimeZone()[0秒] [14-07-22 14:08:54:890 EDT] SpreadsheetApp.getActiveSheet()[0秒] [14-07-22 14:08:55:067 EDT] Sheet.getLastColumn()[0.176秒] [14-07-22 14:08:55:068 EDT] Sheet.getRange([1,23])[0秒] [14-07-22 14:08:55:134 EDT] Range.getValue()[0.064秒] [14-07-22 14:08:55:134 EDT] SpreadsheetApp.getActiveSheet()[0秒] [14-07-22 14:08:55:187 EDT] Sheet.getLastRow()[0.051秒] [14-07-22 14:08:55:237 EDT] Sheet.getLastColumn()[0.049秒] [14-07-22 14:08:55:238 EDT] Sheet.getRange([1,1,592,23])[0秒] [14-07-22 14:08:55:965 EDT] Range.getValues()[0.727秒] [14-07-22 14:14:57:561 EDT]执行失败:超过最长执行时间[总运行时间为362.742秒]
如何确定悬挂的位置/如何加快处理速度?
这是同步功能:
/**
* Syncs the Fusion Table to the form data. Run this every hour or so.
*/
function sync() {
init();
// Get the data in the spreadsheet and convert it to a dictionary.
var sheet = SpreadsheetApp.getActiveSheet();
var lastRow = sheet.getLastRow();
var lastColumn = sheet.getLastColumn();
var spreadsheetData = sheet.getRange(1, 1, lastRow, lastColumn);
var spreadsheetValues = spreadsheetData.getValues();
var columns = spreadsheetValues[0];
var spreadsheetMap = mapRowsByRowId(columns,
spreadsheetValues.slice(1, spreadsheetValues.length));
// Get the columns in the spreadsheet and escape any single quotes
var escapedColumns = [];
for (var i = 0; i < columns.length; i++) {
var columnName = columns[i];
columnName = escapeQuotes(columnName);
escapedColumns.push(columnName);
}
// Get the data from the table and convert to a dictionary.
var query = "SELECT '" + escapedColumns.join("','") + "' FROM " + DOCID;
var ftResults = runSqlWithRetry(query);
if (!ftResults) {
return;
}
var ftMap = mapRowsByRowId(ftResults.columns, ftResults.rows);
// For each row in the Fusion Table, find if the row still exists in the
// spreadsheet. If it exists, make sure the values are the same. If
// they are different, update the Fusion Table data.
// If the row doesn't exist in the spreadsheet, delete the row from the table.
///*
for (var rowId in ftMap) {
var spreadsheetRow = spreadsheetMap[rowId];
if (spreadsheetRow) {
var updates = [];
var tableRow = ftMap[rowId];
for (var column in tableRow) {
if (column === 'rowid') {
continue;
}
var tableValue = tableRow[column];
var spreadsheetValue = spreadsheetRow[column];
if (tableValue != spreadsheetValue) {
spreadsheetValue = processSpreadsheetValue(column, spreadsheetValue);
updates.push("'" + escapeQuotes(column) + "' = '" +
spreadsheetValue + "'");
}
}
// If there are updates, send the UPDATE query.
if (updates.length) {
var query = [];
query.push('UPDATE ');
query.push(DOCID);
query.push(' SET ');
query.push(updates.join(','));
query.push(" WHERE rowid = '");
query.push(rowId);
query.push("'");
runSqlWithRetry(query.join(''));
waitBetweenCalls();
}
} else {
// If the row doesn't exist in the spreadsheet, delete it from the table
runSqlWithRetry('DELETE FROM ' + DOCID + " WHERE rowid = '" +
rowId + "'");
waitBetweenCalls();
}
}
//*/
// Insert all the data into the Fusion Table that failed to insert.
// These rows were given a rowid of -1 or have a blank rowid.
var failedInserts = spreadsheetMap[-1];
for (var i = 0; failedInserts && i < failedInserts.length; i++) {
var rowId = createRecord(failedInserts[i]);
if (!rowId) {
rowId = -1;
}
insertRowId(rowId, failedInserts[i].spreadsheetRowNum);
waitBetweenCalls();
}
}