Skip to content

Check the online project templates once per session - #1766

Open
simonvanlierde wants to merge 1 commit into
LCA-ActivityBrowser:majorfrom
simonvanlierde:perf/template-catalogue-once
Open

simonvanlierde wants to merge 1 commit into
LCA-ActivityBrowser:majorfrom
simonvanlierde:perf/template-catalogue-once

Conversation

@simonvanlierde

Copy link
Copy Markdown

Hi Bernhard,

As you suggested in #1745, AB now fetches the template catalogue from files.brightway.dev once per session instead of on every project switch. On a slow connection, every switch waited for that request on the main thread.

  • fetch_remote_projects() is now cached for the session with lru_cache. ProjectManagerSettingsChapter.sync called it every time, which means every project switch and every Save, Cancel and Restore Defaults in Settings. A failed fetch is cached too, so the list stays empty until you refresh.
  • There's a new "Refresh remote templates" entry in the right-click menu of the Templates tab (Settings > Projects). I left it out of the top menu, since Project > Manage projects already leads there.
  • ProjectNewTemplateMenu (Project > New > Import from template) now rebuilds when it opens, so it picks up a refresh. Templates made with "Create template from project" now also show up there without a restart.

With bw2io's request faked to take 2 s, a project switch took 4.2 s on major and 0.23 s with this change. The test setup keeps two Settings pages alive, so it makes two requests per switch; the app makes one, so expect about half that saving there. I haven't measured it in the real app.

Tests: 2 new tests in tests/test_remote_templates.py (no network, bw2io is faked). Full suite on Python 3.12, Linux, offscreen: 470 passed, 2 skipped, 1 failed. The failure is test_database_delete_multiple ("QAbstractEventDispatcher already deleted" in DatabaseOpen.run), and it fails the same way on major in my setup, so it's not from this change. I couldn't try Windows or macOS.

Checklist

If you have write access (otherwise a maintainer will do this for you):

  • Categorize the PR by setting a good title and adding one of the labels:
    bug, feature, ui, change, documentation, breaking, ci
    as they show up in the changelog. (no write access)
  • Add a milestone to the PR (and related issues, if any) for the intended release. (no write access)
  • Request a review from another developer. (no write access)

Refs #1745

Best,

Simon

- Cache the remote template catalogue for the session, including a failed
  fetch, so a project switch no longer waits on files.brightway.dev.
- Add "Refresh remote templates" to the Templates tab in Settings > Projects.
- Rebuild the "Import from template" menu when it opens, so it shows a
  refreshed catalogue and newly created local templates.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant