[geary/mjog/invert-folder-class-hierarchy: 69/72] engine: Allow endpoints to be specified for RemoteFolder.expand vector
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/mjog/invert-folder-class-hierarchy: 69/72] engine: Allow endpoints to be specified for RemoteFolder.expand vector
- Date: Wed, 3 Mar 2021 11:52:49 +0000 (UTC)
commit 46188c7413e45f5d21981423cdea4c8973418661
Author: Michael Gratton <mike vee net>
Date: Wed Mar 3 20:56:04 2021 +1100
engine: Allow endpoints to be specified for RemoteFolder.expand vector
Allow callers to specify either or both a minimum number and a date by
which to expand a remote folder's vector from the remote. Implement in
`MinimalFolder` using new `ExpandVector` replay op.
src/engine/api/geary-remote-folder.vala | 9 +++-
.../imap-engine/imap-engine-minimal-folder.vala | 53 ++++++++++++++++++++--
test/mock/mock-remote-folder.vala | 9 +++-
3 files changed, 65 insertions(+), 6 deletions(-)
---
diff --git a/src/engine/api/geary-remote-folder.vala b/src/engine/api/geary-remote-folder.vala
index 1d5497579..e280289e7 100644
--- a/src/engine/api/geary-remote-folder.vala
+++ b/src/engine/api/geary-remote-folder.vala
@@ -160,10 +160,17 @@ public interface Geary.RemoteFolder : Folder {
* connection to the server, having the remote folder open, and so
* on.
*
+ * The vector will be attempted to be extended back to both the
+ * date (if given) and by the number of email messages (if
+ * given). If neither are specified no attempt will be made to
+ * expand the vector.
+ *
* This method requires the host is online, an error will be
* thrown if the remote server cannot be reached.
*/
- public abstract async void expand_vector(GLib.Cancellable? cancellable)
+ public abstract async void expand_vector(GLib.DateTime? target_date,
+ uint? target_count,
+ GLib.Cancellable? cancellable)
throws GLib.Error;
}
diff --git a/src/engine/imap-engine/imap-engine-minimal-folder.vala
b/src/engine/imap-engine/imap-engine-minimal-folder.vala
index a3c05b188..e32981c41 100644
--- a/src/engine/imap-engine/imap-engine-minimal-folder.vala
+++ b/src/engine/imap-engine/imap-engine-minimal-folder.vala
@@ -39,7 +39,8 @@ private class Geary.ImapEngine.MinimalFolder : BaseObject,
[Flags]
private enum OpenReason {
MONITOR,
- SYNCHRONISE;
+ SYNCHRONISE,
+ EXPAND_VECTOR,
}
@@ -215,9 +216,23 @@ private class Geary.ImapEngine.MinimalFolder : BaseObject,
}
/** {@inheritDoc} */
- public async void expand_vector(GLib.Cancellable? cancellable)
+ public async void expand_vector(GLib.DateTime? target_date,
+ uint? target_count,
+ GLib.Cancellable? cancellable)
throws GLib.Error {
-
+ if (target_date != null || target_count != null) {
+ if (!(OpenReason.EXPAND_VECTOR in this.remote_opens)) {
+ this.remote_opens |= SYNCHRONISE;
+ try {
+ yield expand_vector_impl(
+ target_date, target_count, cancellable
+ );
+ } finally {
+ this.remote_opens &= ~OpenReason.EXPAND_VECTOR;
+ yield check_remote_session();
+ }
+ }
+ }
}
/**
@@ -1313,6 +1328,38 @@ private class Geary.ImapEngine.MinimalFolder : BaseObject,
return op.created_id;
}
+ /**
+ * Expands the owning folder's vector.
+ */
+ private async void expand_vector_impl(GLib.DateTime? target_date,
+ uint? target_count,
+ GLib.Cancellable cancellable
+ ) throws GLib.Error {
+ var remote = yield claim_remote_session(cancellable);
+
+ // include marked for removed in the count in case this is
+ // being called while a removal is in process, in which case
+ // don't want to expand vector this moment because the vector
+ // is in flux
+ int local_count = yield this.local_folder.get_email_count_async(
+ INCLUDE_MARKED_FOR_REMOVE, cancellable
+ );
+
+ // watch out for attempts to expand vector when it's expanded
+ // as far as it will go
+ if (remote.folder.properties.email_total > local_count) {
+ var op = new ExpandVector(
+ this,
+ this._account.local.required_email_fields,
+ target_date,
+ target_count,
+ cancellable
+ );
+ this.replay_queue.schedule(op);
+ yield op.wait_for_ready_async(cancellable);
+ }
+ }
+
/**
* Checks for changes to {@link EmailFlags} after a folder opens.
*/
diff --git a/test/mock/mock-remote-folder.vala b/test/mock/mock-remote-folder.vala
index 74a700084..e64493ad6 100644
--- a/test/mock/mock-remote-folder.vala
+++ b/test/mock/mock-remote-folder.vala
@@ -186,9 +186,14 @@ public class Mock.RemoteFolder : GLib.Object,
yield void_call_async("synchronise", { cancellable });
}
- public async void expand_vector(GLib.Cancellable? cancellable)
+ public async void expand_vector(GLib.DateTime? target_date,
+ uint? target_count,
+ GLib.Cancellable? cancellable)
throws GLib.Error {
- yield void_call_async("expand_vector", { cancellable });
+ yield void_call_async(
+ "expand_vector",
+ { box_arg(target_date), box_arg(target_count), cancellable }
+ );
}
public virtual Geary.Logging.State to_logging_state() {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]