WebDAV + GTK sync-ui: avoid long delays when accessing configs
The GTK sync-ui does CheckSource() calls on all configured sources, even when not directly opening a config in the UI. This was problematic for a CalDAV/CardDAV source because it ended up talking to the server in WebDAVSource::open(). This violates the principle that open() should be a fast, local operation. Reorganized the code so that the expensive code is done as part of WebDAVSource::beginSync() -> WebDAVSource::contactServer() (for CardDAV) resp. MapSyncSource::beginSync() -> SubSyncSource::begin() -> WebDAVSource::contactServer() (for CalDAV).
This commit is contained in:
parent
6a445deb5c
commit
09a1f839b4
|
@ -32,6 +32,7 @@ class CalDAVSource : public WebDAVSource,
|
|||
virtual std::string getMimeVersion() const { return "2.0"; }
|
||||
|
||||
/* implementation of SubSyncSource interface */
|
||||
virtual void begin() { contactServer(); }
|
||||
virtual void listAllSubItems(SubRevisionMap_t &revisions);
|
||||
virtual SubItemResult insertSubItem(const std::string &uid, const std::string &subid,
|
||||
const std::string &item);
|
||||
|
|
|
@ -280,6 +280,11 @@ void WebDAVSource::replaceHTMLEntities(std::string &item)
|
|||
}
|
||||
|
||||
void WebDAVSource::open()
|
||||
{
|
||||
// Nothing to do here, expensive initialization is in contactServer().
|
||||
}
|
||||
|
||||
void WebDAVSource::contactServer()
|
||||
{
|
||||
int timeoutSeconds = m_settings->timeoutSeconds();
|
||||
int retrySeconds = m_settings->retrySeconds();
|
||||
|
|
|
@ -47,6 +47,13 @@ class WebDAVSource : public TrackingSyncSource, private boost::noncopyable
|
|||
static void replaceHTMLEntities(std::string &item);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Initialize HTTP session and locate the right collection.
|
||||
* To be called after open() to do the heavy initializtion
|
||||
* work.
|
||||
*/
|
||||
void contactServer();
|
||||
|
||||
/* implementation of SyncSource interface */
|
||||
virtual void open();
|
||||
virtual bool isEmpty();
|
||||
|
@ -55,6 +62,12 @@ class WebDAVSource : public TrackingSyncSource, private boost::noncopyable
|
|||
void getSynthesisInfo(SynthesisInfo &info,
|
||||
XMLConfigFragments &fragments);
|
||||
|
||||
/** intercept TrackingSyncSource::beginSync() to do the expensive initialization */
|
||||
virtual void beginSync(const std::string &lastToken, const std::string &resumeToken) {
|
||||
contactServer();
|
||||
TrackingSyncSource::beginSync(lastToken, resumeToken);
|
||||
}
|
||||
|
||||
/* implementation of TrackingSyncSource interface */
|
||||
virtual void listAllItems(RevisionMap_t &revisions);
|
||||
virtual InsertItemResult insertItem(const string &luid, const std::string &item, bool raw);
|
||||
|
|
|
@ -94,6 +94,9 @@ class SubSyncSource : virtual public SyncSourceBase
|
|||
*/
|
||||
typedef map<string, pair<string, set<string> > > SubRevisionMap_t;
|
||||
|
||||
/** called after open() and before any of the following methods */
|
||||
virtual void begin() = 0;
|
||||
|
||||
virtual void listAllSubItems(SubRevisionMap_t &revisions) = 0;
|
||||
virtual SubItemResult insertSubItem(const std::string &uid, const std::string &subid,
|
||||
const std::string &item) = 0;
|
||||
|
@ -177,6 +180,7 @@ class MapSyncSource : public TrackingSyncSource,
|
|||
|
||||
virtual Databases getDatabases() { return dynamic_cast<SyncSource &>(*m_sub).getDatabases(); }
|
||||
virtual void open() { dynamic_cast<SyncSource &>(*m_sub).open(); }
|
||||
virtual void beginSync(const std::string &lastToken, const std::string &resumeToken) { m_sub->begin(); TrackingSyncSource::beginSync(lastToken, resumeToken); }
|
||||
virtual bool isEmpty() { return dynamic_cast<SyncSource &>(*m_sub).getOperations().m_isEmpty(); }
|
||||
virtual void listAllItems(SyncSourceRevisions::RevisionMap_t &revisions);
|
||||
virtual InsertItemResult insertItem(const std::string &luid, const std::string &item, bool raw);
|
||||
|
|
Loading…
Reference in a new issue