logger: do not regenerate whole tab selector if no change

This commit is contained in:
gorhill 2015-05-18 08:12:35 -04:00
parent 92be1c2a12
commit ea4f4cee72
4 changed files with 23 additions and 10 deletions

View File

@ -136,6 +136,7 @@ return {
selfieAfter: 23 * oneMinute, selfieAfter: 23 * oneMinute,
pageStores: {}, pageStores: {},
pageStoresToken: 0,
storageQuota: vAPI.storage.QUOTA_BYTES, storageQuota: vAPI.storage.QUOTA_BYTES,
storageUsed: 0, storageUsed: 0,

View File

@ -48,7 +48,7 @@ var lastVarDataIndex = 4; // currently, d0-d3
var maxEntries = 5000; var maxEntries = 5000;
var noTabId = ''; var noTabId = '';
var allTabIds = {}; var allTabIds = {};
var allTabIdsToken;
var hiddenTemplate = document.querySelector('#hiddenTemplate > span'); var hiddenTemplate = document.querySelector('#hiddenTemplate > span');
var prettyRequestTypes = { var prettyRequestTypes = {
@ -347,10 +347,6 @@ var renderLogEntries = function(response) {
var synchronizeTabIds = function(newTabIds) { var synchronizeTabIds = function(newTabIds) {
var oldTabIds = allTabIds; var oldTabIds = allTabIds;
// Neuter rows for which a tab does not exist anymore
// TODO: sort to avoid using indexOf
var autoDeleteVoidRows = !!vAPI.localStorage.getItem('loggerAutoDeleteVoidRows'); var autoDeleteVoidRows = !!vAPI.localStorage.getItem('loggerAutoDeleteVoidRows');
var rowVoided = false; var rowVoided = false;
var trs; var trs;
@ -443,8 +439,12 @@ var onLogBufferRead = function(response) {
} }
// Neuter rows for which a tab does not exist anymore // Neuter rows for which a tab does not exist anymore
// TODO: sort to avoid using indexOf var rowVoided = false;
var rowVoided = synchronizeTabIds(response.tabIds); if ( response.tabIdsToken !== allTabIdsToken ) {
rowVoided = synchronizeTabIds(response.tabIds);
allTabIdsToken = response.tabIdsToken;
}
renderLogEntries(response); renderLogEntries(response);
if ( rowVoided ) { if ( rowVoided ) {

View File

@ -1210,7 +1210,8 @@ var onMessage = function(request, sender, callback) {
entries: µb.logger.readAll(), entries: µb.logger.readAll(),
maxEntries: µb.userSettings.requestLogMaxEntries, maxEntries: µb.userSettings.requestLogMaxEntries,
noTabId: vAPI.noTabId, noTabId: vAPI.noTabId,
tabIds: tabIds tabIds: tabIds,
tabIdsToken: µb.pageStoresToken
}; };
break; break;

View File

@ -523,6 +523,8 @@ vAPI.tabs.registerListeners();
// Tab is not bound // Tab is not bound
if ( !pageStore ) { if ( !pageStore ) {
this.updateTitle(tabId);
this.pageStoresToken = Date.now();
return this.pageStores[tabId] = this.PageStore.factory(tabId); return this.pageStores[tabId] = this.PageStore.factory(tabId);
} }
@ -538,13 +540,14 @@ vAPI.tabs.registerListeners();
return pageStore; return pageStore;
} }
this.updateTitle(tabId);
// Rebind according to context. We rebind even if the URL did not change, // Rebind according to context. We rebind even if the URL did not change,
// as maybe the tab was force-reloaded, in which case the page stats must // as maybe the tab was force-reloaded, in which case the page stats must
// be all reset. // be all reset.
pageStore.reuse(context); pageStore.reuse(context);
this.updateTitle(tabId);
this.pageStoresToken = Date.now();
return pageStore; return pageStore;
}; };
@ -556,6 +559,7 @@ vAPI.tabs.registerListeners();
if ( pageStore !== undefined ) { if ( pageStore !== undefined ) {
pageStore.dispose(); pageStore.dispose();
delete this.pageStores[tabId]; delete this.pageStores[tabId];
this.pageStoresToken = Date.now();
} }
}; };
@ -605,11 +609,18 @@ vAPI.tabs.registerListeners();
if ( pageStore === null ) { if ( pageStore === null ) {
return tryNoMore(tabId); return tryNoMore(tabId);
} }
// Firefox needs this: if you detach a tab, the new tab won't have
// its rawURL set. Concretely, this causes the logger to report an
// entry to itself in the logger's tab selector.
// TODO: Investigate for a fix vAPI-side.
pageStore.rawURL = tab.url;
this.pageStoresToken = Date.now();
if ( !tab.title && tryAgain(tabId) ) { if ( !tab.title && tryAgain(tabId) ) {
return; return;
} }
tryNoMore(tabId); tryNoMore(tabId);
pageStore.title = tab.title || tab.url || ''; pageStore.title = tab.title || tab.url || '';
this.pageStoresToken = Date.now();
}; };
var updateTitle = function(tabId) { var updateTitle = function(tabId) {