mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 15:07:28 -06:00
Performance increase for obtaining LocalPackages
The speed increase on the function when running Yappi `LocalPackageList.updatePackages` | original | now | |----------|------| | 14 ms | 4 ms | Contributes to CURA-8558
This commit is contained in:
parent
3a94fc0ced
commit
e01e47b8fa
1 changed files with 9 additions and 20 deletions
|
@ -1,8 +1,8 @@
|
||||||
# Copyright (c) 2021 Ultimaker B.V.
|
# Copyright (c) 2021 Ultimaker B.V.
|
||||||
# Cura is released under the terms of the LGPLv3 or higher.
|
# Cura is released under the terms of the LGPLv3 or higher.
|
||||||
|
|
||||||
from typing import Any, Dict, Generator, TYPE_CHECKING
|
from typing import Any, Dict, Generator, List, Optional, TYPE_CHECKING
|
||||||
from PyQt5.QtCore import pyqtSlot, Qt
|
from PyQt5.QtCore import pyqtSlot, QObject
|
||||||
|
|
||||||
from UM.i18n import i18nCatalog
|
from UM.i18n import i18nCatalog
|
||||||
|
|
||||||
|
@ -11,9 +11,6 @@ from cura.CuraApplication import CuraApplication
|
||||||
from .PackageList import PackageList
|
from .PackageList import PackageList
|
||||||
from .PackageModel import PackageModel # The contents of this list.
|
from .PackageModel import PackageModel # The contents of this list.
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
from PyQt5.QtCore import QObject
|
|
||||||
|
|
||||||
catalog = i18nCatalog("cura")
|
catalog = i18nCatalog("cura")
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,7 +28,7 @@ class LocalPackageList(PackageList):
|
||||||
}
|
}
|
||||||
} # The section headers to be used for the different package categories
|
} # The section headers to be used for the different package categories
|
||||||
|
|
||||||
def __init__(self, parent: "QObject" = None) -> None:
|
def __init__(self, parent: Optional[QObject] = None) -> None:
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self._manager = CuraApplication.getInstance().getPackageManager()
|
self._manager = CuraApplication.getInstance().getPackageManager()
|
||||||
self._has_footer = False
|
self._has_footer = False
|
||||||
|
@ -51,22 +48,14 @@ class LocalPackageList(PackageList):
|
||||||
""" Obtain the local packages.
|
""" Obtain the local packages.
|
||||||
|
|
||||||
The list is sorted per category as in the order of the PACKAGE_SECTION_HEADER dictionary, whereas the packages
|
The list is sorted per category as in the order of the PACKAGE_SECTION_HEADER dictionary, whereas the packages
|
||||||
for the sections are sorted alphabetically on the display name
|
for the sections are sorted alphabetically on the display name. These sorted sections are then added to the items
|
||||||
"""
|
"""
|
||||||
|
package_info = list(self._allPackageInfo())
|
||||||
sorted_sections = {}
|
sorted_sections: List[Dict[str, PackageModel]] = []
|
||||||
# Filter the packages per section title and sort these alphabetically
|
|
||||||
for section in self._getSections():
|
for section in self._getSections():
|
||||||
packages = filter(lambda p: p.sectionTitle == section, self._allPackageInfo())
|
packages = filter(lambda p: p.sectionTitle == section, package_info)
|
||||||
sorted_sections[section] = sorted(packages, key = lambda p: p.displayName)
|
sorted_sections.extend([{"package": p} for p in sorted(packages, key = lambda p: p.displayName)])
|
||||||
|
self.setItems(sorted_sections)
|
||||||
# Append the order PackageModels to the list
|
|
||||||
for sorted_section in sorted_sections.values():
|
|
||||||
for package_data in sorted_section:
|
|
||||||
self.appendItem({"package": package_data})
|
|
||||||
|
|
||||||
self.setIsLoading(False)
|
|
||||||
self.setHasMore(False) # All packages should have been loaded at this time
|
|
||||||
|
|
||||||
def _getSections(self) -> Generator[str, None, None]:
|
def _getSections(self) -> Generator[str, None, None]:
|
||||||
""" Flatten and order the PACKAGE_SECTION_HEADER such that it can be used in obtaining the packages in the
|
""" Flatten and order the PACKAGE_SECTION_HEADER such that it can be used in obtaining the packages in the
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue