~marcustomlinson/unity-scopes-shell/lp-1583055

« back to all changes in this revision

Viewing changes to src/Unity/scope.cpp

  • Committer: CI Train Bot
  • Author(s): Marcus Tomlinson
  • Date: 2016-05-05 09:41:13 UTC
  • mfrom: (300.2.15 lp-1567429)
  • Revision ID: ci-train-bot@canonical.com-20160505094113-jsroqj3r64eul5e9
Update child scopes in a background thread to greatly improve the performance of Scope::settings() Fixes: #1567429
Approved by: Pawel Stolowski

Show diffs side-by-side

added added

removed removed

Lines of Context:
92
92
    , m_hasNavigation(false)
93
93
    , m_favorite(false)
94
94
    , m_initialQueryDone(false)
 
95
    , m_childScopesDirty(true)
95
96
    , m_searchController(new CollectionController)
96
97
    , m_activationController(new CollectionController)
97
98
    , m_status(Status::Okay)
131
132
 
132
133
Scope::~Scope()
133
134
{
 
135
    m_childScopesFuture.waitForFinished();
134
136
}
135
137
 
136
138
void Scope::processSearchChunk(PushEvent* pushEvent)
253
255
{
254
256
    // refresh Settings view if needed
255
257
    if (require_child_scopes_refresh()) {
 
258
        m_childScopesDirty = true;
256
259
        update_child_scopes();
257
260
    }
258
261
 
729
732
 
730
733
    setSearchInProgress(true);
731
734
 
 
735
    // If applicable, update this scope's child scopes now, as part of the search process
 
736
    // (i.e. while the loading bar is visible).
 
737
    update_child_scopes();
 
738
 
732
739
    if (m_proxy) {
733
740
        scopes::SearchMetadata meta(m_cardinality, QLocale::system().name().toStdString(), m_formFactor.toStdString());
734
741
        auto const userAgent = m_scopesInstance->userAgentString();
896
903
 
897
904
unity::shell::scopes::SettingsModelInterface* Scope::settings() const
898
905
{
899
 
    if (m_settingsModel && m_scopesInstance)
900
 
    {
901
 
        m_settingsModel->update_child_scopes(m_scopesInstance->getAllMetadata());
902
 
    }
903
906
    return m_settingsModel.data();
904
907
}
905
908
 
914
917
 
915
918
void Scope::update_child_scopes()
916
919
{
917
 
    if (m_settingsModel && m_scopesInstance)
 
920
    // only run the update if child scopes have changed
 
921
    if (m_childScopesDirty && m_settingsModel && m_scopesInstance)
918
922
    {
919
 
        m_settingsModel->update_child_scopes(m_scopesInstance->getAllMetadata());
 
923
        // reset the flag so that re-entering this method won't restart the update unnecessarily
 
924
        m_childScopesDirty = false;
 
925
 
 
926
        // just in case we have another update still running, wait here for it to complete
 
927
        m_childScopesFuture.waitForFinished();
 
928
 
 
929
        // run the update in a seperate thread
 
930
        m_childScopesFuture = QtConcurrent::run([this]
 
931
        {
 
932
            m_settingsModel->update_child_scopes(m_scopesInstance->getAllMetadata());
 
933
        });
920
934
    }
921
935
}
922
936
 
1267
1281
    m_activationController->invalidate();
1268
1282
}
1269
1283
 
 
1284
void Scope::invalidateChildScopes()
 
1285
{
 
1286
    m_childScopesDirty = true;
 
1287
}
 
1288
 
1270
1289
void Scope::invalidateResults()
1271
1290
{
1272
1291
    if (m_isActive) {