Make search update process optional when ImapDB.Account opened

This allows ImapDB unit tests to avoid running the process when it
really doesn't need to be run. Should fix anther criticial about
ImapDB being null (see previous commit).
This commit is contained in:
Michael Gratton 2019-06-23 13:26:07 +10:00
parent 0f4eda5f45
commit 56e0fb7543
2 changed files with 16 additions and 12 deletions

View file

@ -7,7 +7,6 @@
*/
private class Geary.ImapDB.Account : BaseObject {
private const int POPULATE_SEARCH_TABLE_DELAY_SEC = 5;
// These characters are chosen for being commonly used to continue a single word (such as
// extended last names, i.e. "Lars-Eric") or in terms commonly searched for in an email client,
@ -327,16 +326,6 @@ private class Geary.ImapDB.Account : BaseObject {
}
background_cancellable = new Cancellable();
// Kick off a background update of the search table, but since the database is getting
// hammered at startup, wait a bit before starting the update ... use the ordinal to
// stagger these being fired off (important for users with many accounts registered)
int account_sec = account_information.ordinal.clamp(0, 10);
Timeout.add_seconds(POPULATE_SEARCH_TABLE_DELAY_SEC + account_sec, () => {
populate_search_table_async.begin(background_cancellable);
return false;
});
}
public async void close_async(Cancellable? cancellable) throws Error {
@ -1370,7 +1359,7 @@ private class Geary.ImapDB.Account : BaseObject {
}, cancellable);
}
private async void populate_search_table_async(Cancellable? cancellable) {
public async void populate_search_table(Cancellable? cancellable) {
debug("%s: Populating search table", account_information.id);
try {
while (!yield populate_search_table_batch_async(50, cancellable)) {

View file

@ -167,6 +167,21 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.Account {
yield this.imap.start(cancellable);
this.queue_operation(new StartPostie(this));
// Kick off a background update of the search table, but since
// the database is getting hammered at startup, wait a bit
// before starting the update ... use the ordinal to stagger
// these being fired off (important for users with many
// accounts registered).
//
// This is an example of an operation for which we need an
// engine-wide operation queue, not just an account-wide
// queue.
const int POPULATE_DELAY_SEC = 5;
int account_sec = this.information.ordinal.clamp(0, 10);
Timeout.add_seconds(POPULATE_DELAY_SEC + account_sec, () => {
this.local.populate_search_table.begin(cancellable);
return false;
});
}
public override async void close_async(Cancellable? cancellable = null) throws Error {