Skip to content

Commit 9020176

Browse files
committed
Fix people API loading racing with sheets API loading
This seems like it is a race on loading sheets and checking if sheets is loaded, which caused an array to be given to callers of gwrap.load rather than the single API that was asked for, breaking People API calls. Added a new case to handle asking for a specific API even when multiple new ones are seen in processDelta, and a log so we can check if the array is ever returned We are super suspicious of this code even needing to exist. It seems like an extra, complex, over-abstracted wrapper around just using gapi directly. This commit also has a change to make sure if LOG_USER or LOG_URL aren't set, they don't stop the logger from loading.
1 parent 0b5fd83 commit 9020176

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

src/web/js/google-apis/api-wrapper.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,10 +394,23 @@ function loadAPIWrapper(immediate) {
394394
}
395395

396396
function processDelta() {
397+
debugger;
397398
var newKeys = Object.keys(gapi.client)
398399
.filter(function(k) {return (preKeys.indexOf(k) === -1);});
399400
var ret;
400-
if (newKeys.length > 1) {
401+
if (params.name && newKeys.indexOf(params.name) !== -1) {
402+
// When we requested a specific API by name, return only that one.
403+
// Other new keys (from concurrent loads) will be picked up by
404+
// their own loadAPI calls. Process all keys to populate the cache,
405+
// but only return the one we asked for.
406+
newKeys.forEach(processKey);
407+
ret = _GWRAP_APIS[params.name];
408+
} else if (newKeys.length > 1) {
409+
// NOTE(joe, Apr 2026): We added this to diagnose if it actually ever
410+
// happens in prod that we return a list of new APIs.
411+
// We think it probably doesn't based on call sites, but don't want to
412+
// break anything.
413+
logger.log('processdelta-multi-key-return', { newKeys, preKeys });
401414
ret = newKeys.map(processKey);
402415
} else if (params.name && newKeys.length === 0) {
403416
// Hack to make drive-loading happy on login

src/web/js/log.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ var AJAXBackend = function (url) {
3838
}
3939

4040
var backend;
41-
if(LOG_URL && LOG_USER) {
41+
if(window.LOG_URL && window.LOG_USER) {
4242
backend = new FetchWithCredsBackend(LOG_URL, LOG_USER, LOG_PASSWORD);
4343
}
44-
else if(LOG_URL) {
44+
else if(window.LOG_URL) {
4545
backend = new AJAXBackend(LOG_URL);
4646
}
4747
else {

0 commit comments

Comments
 (0)