Bug 1642952 - Modern search engine configuration no longer needs to 'rebuild' the cache on startup. r=daleharvey

For the modern configuration, the rebuild and non-rebuild cache paths are virtually identical - we now load the app-provided engines, then the user engines. The non-rebuild cache route also applies WebExtensions found by the add-on manager whilst we're starting up, but we can apply that to the rebuild cache route as well.

Differential Revision: https://phabricator.services.mozilla.com/D80056
This commit is contained in:
Mark Banner 2020-06-18 09:58:20 +00:00
parent ae68ef21b3
commit b5a78533f6

View File

@ -922,18 +922,19 @@ SearchService.prototype = {
logConsole.debug("_loadEngines: start");
let engines = await this._findEngineSelectorEngines();
let buildID = Services.appinfo.platformBuildID;
let rebuildCache =
gEnvironment.get("RELOAD_ENGINES") ||
let enginesCorrupted = false;
// If this is an update of Firefox, then the expected engines might have
// changed so we can't do the corrupt cache check.
let majorChange =
!cache.engines ||
cache.version != SearchUtils.CACHE_VERSION ||
cache.locale != Services.locale.requestedLocale ||
cache.buildID != buildID;
cache.buildID != Services.appinfo.platformBuildID;
let enginesCorrupted = false;
if (!rebuildCache) {
const notInCacheEngines = engine => {
return !cache.builtInEngineList.find(details => {
if (!majorChange) {
const engineInCacheList = engine => {
return cache.builtInEngineList.find(details => {
return (
engine.webExtension.id == details.id &&
engine.webExtension.locale == details.locale
@ -941,17 +942,17 @@ SearchService.prototype = {
});
};
rebuildCache =
!cache.builtInEngineList ||
cache.builtInEngineList.length != engines.length ||
engines.some(notInCacheEngines);
if (
!rebuildCache &&
// If the cache builtInEngineList matches what we expect from the
// selector engines...
cache.builtInEngineList &&
cache.builtInEngineList.length == engines.length &&
engines.every(engineInCacheList) &&
// ...and the cached built-in cached do not match our expectation...
cache.engines.filter(e => e._isAppProvided).length !=
cache.builtInEngineList.length
) {
rebuildCache = true;
// ...then the cache is corrupted in some manner.
enginesCorrupted = true;
}
}
@ -961,30 +962,10 @@ SearchService.prototype = {
enginesCorrupted
);
if (!rebuildCache) {
logConsole.debug("_loadEngines: loading from cache directories");
const newEngines = await this._loadEnginesFromConfig(engines, isReload);
for (let engine of newEngines) {
this._addEngineToStore(engine);
}
// TODO: Remove the second argument when we remove the legacy config
// (the function should then always skip-builtin engines).
this._loadEnginesFromCache(cache, true);
this._loadEnginesMetadataFromCache(cache);
if (this._engines.size) {
logConsole.debug("_loadEngines: done using existing cache");
return;
}
logConsole.debug(
"_loadEngines: No valid engines found in cache. Loading engines from disk."
);
}
logConsole.debug(
"_loadEngines: Absent or outdated cache. Loading engines from disk."
);
let newEngines = await this._loadEnginesFromConfig(engines, isReload);
newEngines.forEach(this._addEngineToStore, this);
for (let engine of newEngines) {
this._addEngineToStore(engine);
}
logConsole.debug(
"_loadEngines: loading",
@ -998,15 +979,13 @@ SearchService.prototype = {
true
);
}
this._startupExtensions.clear();
logConsole.debug(
"_loadEngines: loading user-installed engines from the obsolete cache"
);
this._loadEnginesFromCache(cache, true);
this._loadEnginesMetadataFromCache(cache);
logConsole.debug("_loadEngines: done using rebuilt cache");
logConsole.debug("_loadEngines: done");
},
/**
@ -1564,6 +1543,8 @@ SearchService.prototype = {
}
},
// TODO: Remove the second argument when we remove gModernConfig.
// (the function should then always skip-builtin engines).
_loadEnginesFromCache(cache, skipAppProvided) {
if (!cache.engines) {
return;
@ -2521,6 +2502,22 @@ SearchService.prototype = {
initEngine = false,
isReload
) {
// If we're in the startup cycle, and we've already loaded this engine,
// then we use the existing one rather than trying to start from scratch.
// This also avoids console errors.
if (extension.startupReason == "APP_STARTUP") {
let engine = this._getEngineByWebExtensionDetails({
id: extension.id,
locale,
});
if (engine) {
logConsole.debug(
"Engine already loaded via cache, skipping due to APP_STARTUP:",
extension.id
);
return engine;
}
}
let params = await this.getEngineParams(extension, manifest, locale, {
initEngine,
});