Skip to content

Commit

Permalink
Optimize loading pattern list
Browse files Browse the repository at this point in the history
Reduce the number of needed libzypp calls to just a single call
  • Loading branch information
lslezak committed Sep 26, 2023
1 parent 5069337 commit 29301f1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions service/lib/agama/dbus/software/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ def initialize(backend, logger)
dbus_method :ListPatterns, "in Filtered:b, out Result:a{s(ssssi)}" do |filtered|
[
backend.patterns(filtered).each_with_object({}) do |pattern, result|
# make sure all attributes are already preloaded, adjust the "patterns" method
# in service/lib/agama/software/manager.rb when changing this list
value = [
pattern.category,
pattern.description,
Expand Down
5 changes: 4 additions & 1 deletion service/lib/agama/software/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,10 @@ def provision_selected?(tag)
# Filtering criteria can change.
# @return [Array<Y2Packager::Resolvable>]
def patterns(filtered)
patterns = Y2Packager::Resolvable.find(kind: :pattern)
# huge speed up, preload the used attributes to avoid querying libzypp again,
# see "ListPatterns" method in service/lib/agama/dbus/software/manager.rb
preload = [:category, :description, :icon, :summary, :order, :user_visible]
patterns = Y2Packager::Resolvable.find({ kind: :pattern }, preload)
patterns = patterns.select(&:user_visible) if filtered

patterns
Expand Down

0 comments on commit 29301f1

Please sign in to comment.