@@ -29100,7 +29100,7 @@ define("extensibility/ExtensionDownloader", function (require, exports, module)
2910029100 */
2910129101
2910229102/*jslint regexp: true */
29103- /*global Phoenix */
29103+ /*global path, logger */
2910429104/*unittests: ExtensionManager*/
2910529105
2910629106/**
@@ -29124,6 +29124,7 @@ define("extensibility/ExtensionManager", function (require, exports, module) {
2912429124 ExtensionLoader = require("utils/ExtensionLoader"),
2912529125 ExtensionUtils = require("utils/ExtensionUtils"),
2912629126 FileSystem = require("filesystem/FileSystem"),
29127+ FileUtils = require("file/FileUtils"),
2912729128 PreferencesManager = require("preferences/PreferencesManager"),
2912829129 Strings = require("strings"),
2912929130 StringUtils = require("utils/StringUtils"),
@@ -29134,6 +29135,47 @@ define("extensibility/ExtensionManager", function (require, exports, module) {
2913429135 "test_extension_registry" : "extension_registry",
2913529136 EXTENSION_REGISTRY_LOCAL_STORAGE_VERSION_KEY = Phoenix.isTestWindow ?
2913629137 "test_extension_registry_version" : "extension_registry_version";
29138+
29139+ // earlier, we used to cache the full uncompressed registry in ls which has a usual size limit of 5mb, and the
29140+ // registry takes a few MB. So we moved this storage and this will clear local storage on any existing installs on
29141+ // next update. This migration code can be removed after July 2025(6 Months).
29142+ localStorage.removeItem(EXTENSION_REGISTRY_LOCAL_STORAGE_KEY);
29143+
29144+ const REGISTRY_CACHE_FILE = Phoenix.isTestWindow ?
29145+ "test_registry_cache.json" : "registry_cache.json";
29146+ const REGISTRY_CACHE_PATH = path.normalize(
29147+ Phoenix.app.getExtensionsDirectory() + "/" + REGISTRY_CACHE_FILE);
29148+ function _getCachedRegistry() {
29149+ // never rejects
29150+ return new Promise((resolve) => {
29151+ const registryFile = FileSystem.getFileForPath(REGISTRY_CACHE_PATH);
29152+ FileUtils.readAsText(registryFile)
29153+ .done(resolve)
29154+ .fail(function (err) {
29155+ console.error(`Registry cache not found ${REGISTRY_CACHE_PATH}`, err);
29156+ resolve(null);
29157+ });
29158+ });
29159+ }
29160+
29161+ function _putCachedRegistry(registryFileText) {
29162+ // never rejects
29163+ return new Promise((resolve) => {
29164+ const registryFile = FileSystem.getFileForPath(REGISTRY_CACHE_PATH);
29165+ FileUtils.writeText(registryFile, registryFileText)
29166+ .done(resolve)
29167+ .fail(function (err) {
29168+ logger.reportError(err, `Registry cache write error ${REGISTRY_CACHE_PATH}`);
29169+ resolve();
29170+ });
29171+ });
29172+ }
29173+
29174+ function _removeCachedRegistry() {
29175+ const registryFile = FileSystem.getFileForPath(REGISTRY_CACHE_PATH);
29176+ return registryFile.unlinkAsync();
29177+ }
29178+
2913729179 // semver.browser is an AMD-compatible module
2913829180 var semver = require("thirdparty/semver.browser");
2913929181
@@ -29303,38 +29345,42 @@ define("extensibility/ExtensionManager", function (require, exports, module) {
2930329345 if(registryVersion.version !== parseInt(currentRegistryVersion)){
2930429346 resolve(registryVersion.version);
2930529347 } else {
29306- const registryJson = localStorage.getItem(EXTENSION_REGISTRY_LOCAL_STORAGE_KEY);
29307- if(!registryJson) {
29308- resolve(registryVersion.version);
29309- // if we dont have anything, best to atlest try to fetch the registry now.
29310- return;
29311- }
29312- reject();
29348+ _getCachedRegistry() // never rejects
29349+ .then(registryJson => {
29350+ if(!registryJson) {
29351+ resolve(registryVersion.version);
29352+ // if we dont have anything, best to atlest try to fetch the registry now.
29353+ return;
29354+ }
29355+ reject();
29356+ });
2931329357 }
2931429358 })
2931529359 .fail(function (err) {
2931629360 console.error("error Fetching Extension Registry version", err);
29317- const registryJson = localStorage.getItem(EXTENSION_REGISTRY_LOCAL_STORAGE_KEY);
29318- if(!registryJson) {
29319- resolve(1); // if we dont have anything, best to atlest try to fetch the registry now.
29320- return;
29321- }
29322- reject();
29361+ _getCachedRegistry() // never rejects
29362+ .then(registryJson => {
29363+ if(!registryJson) {
29364+ resolve(1); // if we dont have anything, best to atlest try to fetch the registry now.
29365+ return;
29366+ }
29367+ reject();
29368+ });
2932329369 });
2932429370 });
2932529371 }
2932629372
29327- function _patchDownloadCounts() {
29328- let registryJson = localStorage.getItem(EXTENSION_REGISTRY_LOCAL_STORAGE_KEY );
29373+ async function _patchDownloadCounts() {
29374+ let registryJson = await _getCachedRegistry( );
2932929375 if(!registryJson){
2933029376 return;
2933129377 }
2933229378 $.ajax({
2933329379 url: brackets.config.extension_registry_popularity,
2933429380 dataType: "json",
2933529381 cache: false
29336- }).done(function (popularity) {
29337- registryJson = localStorage.getItem(EXTENSION_REGISTRY_LOCAL_STORAGE_KEY );
29382+ }).done(async function (popularity) {
29383+ registryJson = await _getCachedRegistry( );
2933829384 let registry = JSON.parse(registryJson);
2933929385 for(let key of Object.keys(popularity)){
2934029386 if(registry[key]) {
@@ -29344,7 +29390,7 @@ define("extensibility/ExtensionManager", function (require, exports, module) {
2934429390 || null;
2934529391 }
2934629392 }
29347- localStorage.setItem(EXTENSION_REGISTRY_LOCAL_STORAGE_KEY, JSON.stringify(registry));
29393+ _putCachedRegistry( JSON.stringify(registry));
2934829394 });
2934929395 }
2935029396
@@ -29388,6 +29434,7 @@ define("extensibility/ExtensionManager", function (require, exports, module) {
2938829434 pendingDownloadRegistry = new $.Deferred();
2938929435
2939029436 function _updateRegistry(newVersion) {
29437+ console.log("downloading extension registry: ", newVersion, brackets.config.extension_registry);
2939129438 $.ajax({
2939229439 url: brackets.config.extension_registry,
2939329440 dataType: "json",
@@ -29396,20 +29443,20 @@ define("extensibility/ExtensionManager", function (require, exports, module) {
2939629443 .done(function (registry) {
2939729444 registry = _filterIncompatibleEntries(registry);
2939829445 localStorage.setItem(EXTENSION_REGISTRY_LOCAL_STORAGE_VERSION_KEY, newVersion);
29399- localStorage.setItem(EXTENSION_REGISTRY_LOCAL_STORAGE_KEY, JSON.stringify(registry));
29400- if(!pendingDownloadRegistry.alreadyResolvedFromCache){
29401- _populateExtensions(registry);
29402- pendingDownloadRegistry.resolve();
29403- }
29446+ _putCachedRegistry(JSON.stringify(registry)).then(()=>{
29447+ if(!pendingDownloadRegistry.alreadyResolvedFromCache){
29448+ _populateExtensions(registry);
29449+ pendingDownloadRegistry.resolve();
29450+ }
29451+ }).finally(()=>{
29452+ pendingDownloadRegistry = null;
29453+ });
2940429454 })
2940529455 .fail(function (err) {
2940629456 console.error("error Fetching Extension Registry", err);
2940729457 if(!pendingDownloadRegistry.alreadyResolvedFromCache){
2940829458 pendingDownloadRegistry.reject();
2940929459 }
29410- })
29411- .always(function () {
29412- // Make sure to clean up the pending registry so that new requests can be made.
2941329460 pendingDownloadRegistry = null;
2941429461 });
2941529462 }
@@ -29419,26 +29466,28 @@ define("extensibility/ExtensionManager", function (require, exports, module) {
2941929466 return pendingDownloadRegistry.promise();
2942029467 }
2942129468
29422- const registryJson = localStorage.getItem(EXTENSION_REGISTRY_LOCAL_STORAGE_KEY);
29423- if(registryJson) {
29424- // we always immediately but after the promise chain is setup after function return (some bug sigh)
29425- // resolve for ui responsiveness and then check for updates.
29426- setTimeout(()=>{
29427- Metrics.countEvent(Metrics.EVENT_TYPE.EXTENSIONS, "registry", "cachedUse");
29428- let registry = JSON.parse(registryJson);
29429- registry = _filterIncompatibleEntries(registry);
29430- _populateExtensions(registry);
29431- pendingDownloadRegistry.resolve();
29432- }, 0);
29433- pendingDownloadRegistry.alreadyResolvedFromCache = true;
29434- }
29435- // check for latest updates even if we have cache
29436- _shouldUpdateExtensionRegistry()
29437- .then(_updateRegistry)
29438- .catch(()=>{
29439- pendingDownloadRegistry = null;
29469+ _getCachedRegistry() // never rejects
29470+ .then(registryJson => {
29471+ if(registryJson) {
29472+ // we always immediately but after the promise chain is setup after function return (some bug sigh)
29473+ // resolve for ui responsiveness and then check for updates.
29474+ setTimeout(()=>{
29475+ Metrics.countEvent(Metrics.EVENT_TYPE.EXTENSIONS, "registry", "cachedUse");
29476+ let registry = JSON.parse(registryJson);
29477+ registry = _filterIncompatibleEntries(registry);
29478+ _populateExtensions(registry);
29479+ pendingDownloadRegistry.resolve();
29480+ }, 0);
29481+ pendingDownloadRegistry.alreadyResolvedFromCache = true;
29482+ }
29483+ // check for latest updates even if we have cache
29484+ _shouldUpdateExtensionRegistry()
29485+ .then(_updateRegistry)
29486+ .catch(()=>{
29487+ console.log("Registry update skipped");
29488+ });
29489+ _patchDownloadCounts();
2944029490 });
29441- _patchDownloadCounts();
2944229491
2944329492 return pendingDownloadRegistry.promise();
2944429493 }
@@ -30002,7 +30051,9 @@ define("extensibility/ExtensionManager", function (require, exports, module) {
3000230051 exports._reset = _reset;
3000330052 exports._setExtensions = _setExtensions;
3000430053 if(Phoenix.isTestWindow){
30005- exports.EXTENSION_REGISTRY_LOCAL_STORAGE_KEY = EXTENSION_REGISTRY_LOCAL_STORAGE_KEY;
30054+ exports._getCachedRegistry = _getCachedRegistry;
30055+ exports._putCachedRegistry = _putCachedRegistry;
30056+ exports._removeCachedRegistry = _removeCachedRegistry;
3000630057 }
3000730058});
3000830059
0 commit comments