From df90a4aad13125bcb04f28a4ea423642e38b007a Mon Sep 17 00:00:00 2001 From: Wesley Schwengle Date: Wed, 20 Mar 2019 17:59:12 +0100 Subject: [PATCH 1/2] Decrease the time for the cli app to do things When the local blob version and the remote version are the same skip downloading a new blob and just continue with the current blob. This could potentially shave 300ms (or more, I've seen close to 2 seconds in my browser) when the blob hasn't been updated on the remote side. There is still a small performance hit on `login_check.php` but I cannot think of logical ways why we would increase the timeout, the 5 seconds that is place now make sense to me as you want to display things. Maybe there should be a post action on any command that has `--sync=auto` so subsequent calls have a blob in sync and would cause slowness of the CLI app. Fixes: #475 Signed-off-by: Wesley Schwengle --- blob.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/blob.c b/blob.c index b71ab69e..3f704ae4 100644 --- a/blob.c +++ b/blob.c @@ -910,15 +910,19 @@ static struct blob *blob_get_latest(struct session *session, const unsigned char local = local_blob(key, &session->private_key); if (!local) return lastpass_get_blob(session, key); + remote_version = lastpass_get_blob_version(session, key); + if (remote_version == 0) { blob_free(local); return NULL; } - if (local->version < remote_version || (local->local_version && local->version == remote_version)) { + + if (remote_version > local->version) { blob_free(local); return lastpass_get_blob(session, key); } + config_touch("blob"); return local; } From 37800a9c7d43f0c3c99edda736f59701a67b161e Mon Sep 17 00:00:00 2001 From: Wesley Schwengle Date: Wed, 20 Mar 2019 19:49:32 +0100 Subject: [PATCH 2/2] Refactor blob_load Signed-off-by: Wesley Schwengle --- blob.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/blob.c b/blob.c index 3f704ae4..69d9f445 100644 --- a/blob.c +++ b/blob.c @@ -942,19 +942,20 @@ static time_t auto_sync_time(void) struct blob *blob_load(enum blobsync sync, struct session *session, const unsigned char key[KDF_HASH_LEN]) { - if (sync == BLOB_SYNC_AUTO) { - if (!config_exists("blob")) - return blob_get_latest(session, key); - else if (time(NULL) - config_mtime("blob") <= auto_sync_time()) - return local_blob(key, &session->private_key); + if (sync == BLOB_SYNC_YES) return blob_get_latest(session, key); - } else if (sync == BLOB_SYNC_YES) - return blob_get_latest(session, key); - else if (sync == BLOB_SYNC_NO) + + if (sync == BLOB_SYNC_NO) return local_blob(key, &session->private_key); - return NULL; + if (config_exists("blob") && + time(NULL) - config_mtime("blob") < auto_sync_time()) { + return local_blob(key, &session->private_key); + } + + return blob_get_latest(session, key); } + void blob_save(const struct blob *blob, const unsigned char key[KDF_HASH_LEN]) { _cleanup_free_ char *bluffer = NULL;