Bug 1716737 - Introduce auto pagination after a fixed interval to speed up retreaval of search results. r=freaktechnik
Depends on D189620 Differential Revision: https://phabricator.services.mozilla.com/D189667 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
553c4c57dd
Коммит
23e1d15666
|
@ -18,6 +18,8 @@ var { ExtensionSupport } = ChromeUtils.importESModule(
|
||||||
|
|
||||||
ChromeUtils.defineESModuleGetters(this, {
|
ChromeUtils.defineESModuleGetters(this, {
|
||||||
ExtensionContent: "resource://gre/modules/ExtensionContent.sys.mjs",
|
ExtensionContent: "resource://gre/modules/ExtensionContent.sys.mjs",
|
||||||
|
setTimeout: "resource://gre/modules/Timer.sys.mjs",
|
||||||
|
clearTimeout: "resource://gre/modules/Timer.sys.mjs",
|
||||||
});
|
});
|
||||||
|
|
||||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||||
|
@ -2738,12 +2740,29 @@ class MessageList {
|
||||||
this.extension = extension;
|
this.extension = extension;
|
||||||
this.isDone = false;
|
this.isDone = false;
|
||||||
this.pages = [];
|
this.pages = [];
|
||||||
|
this.autoPaginatorTimeout = null;
|
||||||
|
|
||||||
this.addPage();
|
this.addPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
addPage() {
|
addPage() {
|
||||||
|
if (this.autoPaginatorTimeout) {
|
||||||
|
clearTimeout(this.autoPaginatorTimeout);
|
||||||
|
this.autoPaginatorTimeout = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.isDone) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Adding a page will make this.currentPage point to the new page.
|
// Adding a page will make this.currentPage point to the new page.
|
||||||
let previousPage = this.currentPage;
|
let previousPage = this.currentPage;
|
||||||
|
|
||||||
|
// If the current page has no messages, there is no need to add a page.
|
||||||
|
if (previousPage && previousPage.messages.length == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.pages.push(new MessagePage());
|
this.pages.push(new MessagePage());
|
||||||
// The previous page is finished and can be resolved.
|
// The previous page is finished and can be resolved.
|
||||||
if (previousPage) {
|
if (previousPage) {
|
||||||
|
@ -2766,7 +2785,15 @@ class MessageList {
|
||||||
if (this.currentPage.messages.length >= gMessagesPerPage) {
|
if (this.currentPage.messages.length >= gMessagesPerPage) {
|
||||||
this.addPage();
|
this.addPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.currentPage.messages.push(convertMessage(message, this.extension));
|
this.currentPage.messages.push(convertMessage(message, this.extension));
|
||||||
|
|
||||||
|
// Automatically push a new page and return the page with this message after
|
||||||
|
// a fixed amount of time, so that small sets of search results are not held
|
||||||
|
// back until a full page has been found or the entire search has finished.
|
||||||
|
if (!this.autoPaginatorTimeout) {
|
||||||
|
this.autoPaginatorTimeout = setTimeout(this.addPage.bind(this), 1000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
done() {
|
done() {
|
||||||
|
@ -2823,6 +2850,9 @@ var messageListTracker = {
|
||||||
* Add messages to a messageList.
|
* Add messages to a messageList.
|
||||||
*/
|
*/
|
||||||
async _addMessages(messages, messageList) {
|
async _addMessages(messages, messageList) {
|
||||||
|
if (messageList.isDone) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (Array.isArray(messages)) {
|
if (Array.isArray(messages)) {
|
||||||
messages = this._createEnumerator(messages);
|
messages = this._createEnumerator(messages);
|
||||||
}
|
}
|
||||||
|
@ -2960,3 +2990,7 @@ extensions.on("startup", (type, extension) => {
|
||||||
() => new WindowManager(extension)
|
() => new WindowManager(extension)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
extensions.on("shutdown", (type, extension) => {
|
||||||
|
messageListTracker._contextLists.delete(extension);
|
||||||
|
});
|
||||||
|
|
|
@ -744,6 +744,13 @@ this.messages = class extends ExtensionAPIPersistent {
|
||||||
);
|
);
|
||||||
return messageListTracker.getNextPage(messageList);
|
return messageListTracker.getNextPage(messageList);
|
||||||
},
|
},
|
||||||
|
async abortList(messageListId) {
|
||||||
|
let messageList = messageListTracker.getList(
|
||||||
|
messageListId,
|
||||||
|
context.extension
|
||||||
|
);
|
||||||
|
messageList.done();
|
||||||
|
},
|
||||||
async get(messageId) {
|
async get(messageId) {
|
||||||
let msgHdr = messageTracker.getMessage(messageId);
|
let msgHdr = messageTracker.getMessage(messageId);
|
||||||
if (!msgHdr) {
|
if (!msgHdr) {
|
||||||
|
@ -1181,6 +1188,9 @@ this.messages = class extends ExtensionAPIPersistent {
|
||||||
|
|
||||||
if (messages) {
|
if (messages) {
|
||||||
for (let msg of [...messages]) {
|
for (let msg of [...messages]) {
|
||||||
|
if (messageList.isDone) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (await checkSearchCriteria(folder, msg)) {
|
if (await checkSearchCriteria(folder, msg)) {
|
||||||
messageList.addMessage(msg);
|
messageList.addMessage(msg);
|
||||||
}
|
}
|
||||||
|
@ -1189,6 +1199,9 @@ this.messages = class extends ExtensionAPIPersistent {
|
||||||
|
|
||||||
if (includeSubFolders) {
|
if (includeSubFolders) {
|
||||||
for (let subFolder of folder.subFolders) {
|
for (let subFolder of folder.subFolders) {
|
||||||
|
if (messageList.isDone) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
await searchMessages(subFolder, messageList, true);
|
await searchMessages(subFolder, messageList, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1200,9 +1213,12 @@ this.messages = class extends ExtensionAPIPersistent {
|
||||||
includeSubFolders = false
|
includeSubFolders = false
|
||||||
) => {
|
) => {
|
||||||
for (let folder of folders) {
|
for (let folder of folders) {
|
||||||
|
if (messageList.isDone) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
await searchMessages(folder, messageList, includeSubFolders);
|
await searchMessages(folder, messageList, includeSubFolders);
|
||||||
}
|
}
|
||||||
return messageList.done();
|
messageList.done();
|
||||||
};
|
};
|
||||||
|
|
||||||
// Prepare case insensitive me filtering.
|
// Prepare case insensitive me filtering.
|
||||||
|
|
|
@ -414,6 +414,18 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "abortList",
|
||||||
|
"type": "function",
|
||||||
|
"description": "Finalizes the specified list and terminates any process currently still adding messages.",
|
||||||
|
"async": true,
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"name": "messageListId",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "get",
|
"name": "get",
|
||||||
"type": "function",
|
"type": "function",
|
||||||
|
|
Загрузка…
Ссылка в новой задаче