AccountState: Avoid ConnectionCheck if ETag job was just done.

This patch lets a successful etag job check mark a timestamp.
If next time a connection check is requested, it is checked if
the last ETag happened within the last 30 seconds and if so the
connection check can be checked.

This way we avoid half of the PROPFINDs if all goes well.
This commit is contained in:
Klaas Freitag 2015-10-19 11:50:26 +02:00 committed by Markus Goetz
parent 46dbca1bf5
commit 3d7fc711ca
3 changed files with 28 additions and 0 deletions

View file

@ -39,6 +39,7 @@ AccountState::AccountState(AccountPtr account)
SLOT(slotCredentialsFetched(AbstractCredentials*)));
connect(account.data(), SIGNAL(credentialsAsked(AbstractCredentials*)),
SLOT(slotCredentialsAsked(AbstractCredentials*)));
_timeSinceLastETagCheck.invalidate();
}
AccountState::~AccountState()
@ -135,6 +136,11 @@ bool AccountState::isConnectedOrTemporarilyUnavailable() const
return isConnected() || _state == ServiceUnavailable;
}
void AccountState::tagLastSuccessfullETagRequest()
{
_timeSinceLastETagCheck.restart();
}
void AccountState::checkConnectivity(CredentialFetchMode credentialsFetchMode)
{
if (isSignedOut() || _waitingForNewCredentials) {
@ -145,6 +151,15 @@ void AccountState::checkConnectivity(CredentialFetchMode credentialsFetchMode)
qDebug() << "ConnectionValidator already running, ignoring" << account()->displayName();
return;
}
// IF the account is connected the connection check can be skipped
// if the last successful etag check job is not so long ago.
if (isConnected() && _timeSinceLastETagCheck.isValid()
&& _timeSinceLastETagCheck.elapsed() < 30*1000) {
qDebug() << "The last ETag check succeeded within the last 30 secs. No connection check needed!";
return;
}
_credentialsFetchMode = credentialsFetchMode;
ConnectionValidator * conValidator = new ConnectionValidator(account());
_connectionValidator = conValidator;

View file

@ -95,6 +95,14 @@ public:
*/
QString shortDisplayNameForSettings(int width = 0) const;
/** Mark the timestamp when the last successful ETag check happened for
* this account.
* The checkConnectivity() method uses the timestamp to save a call to
* the server to validate the connection if the last successful etag job
* is not so lang away.
*/
void tagLastSuccessfullETagRequest();
private:
void setState(State state);
@ -114,6 +122,7 @@ private:
QStringList _connectionErrors;
bool _waitingForNewCredentials;
CredentialFetchMode _credentialsFetchMode;
QElapsedTimer _timeSinceLastETagCheck;
QPointer<ConnectionValidator> _connectionValidator;
};

View file

@ -365,6 +365,10 @@ void Folder::etagRetreived(const QString& etag)
_lastEtag = etag;
emit scheduleToSync(this);
}
if( _accountState ) {
_accountState->tagLastSuccessfullETagRequest();
}
}
void Folder::etagRetreivedFromSyncEngine(const QString& etag)