[pve-devel] [PATCH common] schema: only check for cycles during build or if forced

Thomas Lamprecht t.lamprecht at proxmox.com
Fri Nov 22 19:15:16 CET 2019


This is costly and only really required during package build.


Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---

whipped up a patch, works fine here, did a build and manual force check by
adding big fat warn "..." below the early-return.

 src/PVE/JSONSchema.pm | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/PVE/JSONSchema.pm b/src/PVE/JSONSchema.pm
index 51c3881..591fb62 100644
--- a/src/PVE/JSONSchema.pm
+++ b/src/PVE/JSONSchema.pm
@@ -6,13 +6,19 @@ use Storable; # for dclone
 use Getopt::Long;
 use Encode::Locale;
 use Encode;
-use Devel::Cycle -quiet; # todo: remove?
 use PVE::Tools qw(split_list $IPV6RE $IPV4RE);
 use PVE::Exception qw(raise);
 use HTTP::Status qw(:constants);
 use Net::IP qw(:PROC);
 use Data::Dumper;
 
+BEGIN {
+    if ($ENV{DEB_BUILD_ARCH} || $ENV{PROXMOX_FORCE_SCHEMA_VALIDATION}) {
+	require Devel::Cycle;
+	import Devel::Cycle -quiet;
+    }
+}
+
 use base 'Exporter';
 
 our @EXPORT_OK = qw(
@@ -1035,9 +1041,9 @@ sub validate {
     my $errors = {};
     $errmsg = "Parameter verification failed.\n" if !$errmsg;
 
-    # todo: cycle detection is only needed for debugging, I guess
-    # we can disable that in the final release
-    # todo: is there a better/faster way to detect cycles?
+    # only check when building a package or told to do so, this is costly
+    return 1 if !($ENV{DEB_BUILD_ARCH} || $ENV{PROXMOX_FORCE_SCHEMA_VALIDATION});
+
     my $cycles = 0;
     find_cycle($instance, sub { $cycles = 1 });
     if ($cycles) {
-- 
2.20.1





More information about the pve-devel mailing list