Blob Blame History Raw
diff --git a/module_build_service/builder/base.py b/module_build_service/builder/base.py
index 7d474d5..4165295 100644
--- a/module_build_service/builder/base.py
+++ b/module_build_service/builder/base.py
@@ -127,7 +127,28 @@ class GenericBuilder(six.with_metaclass(ABCMeta)):
         builder = GenericBuilder.create(
             module.owner, module, config.system, config,
             tag_name=module.koji_tag, components=components)
-        groups = GenericBuilder.default_buildroot_groups(session, module)
+
+        # Getting the groups from PDC can be time consuming, because we need
+        # to get whole dependency tree from PDC, which might result in lot
+        # of calls to PDC, so just get the groups once per module build
+        # and store it in xmd. The buildroot groups of particular module
+        # build don't change during the module built, so it is OK to cache
+        # them like that.
+        mmd = module.mmd()
+        if not "buildroot_groups" in mmd.xmd["mbs"]:
+            build_groups = GenericBuilder.default_buildroot_groups(
+                session, module)
+            # Change to sets to lists, so we can store them in modulemd.
+            for key in build_groups.keys():
+                build_groups[key] = list(build_groups[key])
+            mmd.xmd["mbs"]["buildroot_groups"] = build_groups
+            module.modulemd = mmd.dumps()
+
+        groups = mmd.xmd["mbs"]["buildroot_groups"]
+        # Change to lists to sets, because buildroot_connect expects sets.
+        for key in groups.keys():
+            groups[key] = set(groups[key])
+
         builder.buildroot_connect(groups)
         return builder