Forum: CFEngine Help Subject: Read files once instead of a bunch? Author: sauer Link to topic: https://cfengine.com/forum/read.php?3,26052,26052#msg-26052
So, I have a vars promise in a global bundle (g) which looks like this: g_counted_lines:: "line_count" int => countlinesmatching( ".*", "$(g.file)" ), classes => if_ok("g_counted_lines"); The global bundle is itself referenced from a methods promise in a bundle named init, and init is in the bundle sequence. It appears that my file is being read roughly 18 times. That would make sense, as the methods are done three times, and then each bundle is checked three times, with this happening once in cf-promises and once in cf-agent. I thought that setting a class on ok/repaired in the variable promise might allow me to only parse the variable once, but the 18 readings remain. This would only be a little sketchy if the file wasn't fairly large - but it is. On most of my systems, the file is several thousand lines. This re-reading of the file about 17 times more than neccesary is, well, not so cool in terms of performance impact - or in terms of "making verbose output way more cumbersome". :) Hopefully I'm not the only person for whom this is a problem. :) Has anyone got a better idea on how to work around it? Setting a class based on the isvariable function call works, but just feels a little sketchy to me (due to that whole variable-class dependency thing that we should pretty much universally avoid). I guess it's ok, but I'd prefer the "classes=>" thing I tried above, as it keeps all of the logic right next to each other in one place in the file; using a classes promise type puts the explanation that "this class is set if the varaible exists" logic farther down in the bundle - possibly not even visible at the same time.. Before I go off to open a couple of feature requests, can anyone confirm if a newer version than 3.2.0 either 1) recognizes that a file hasn't changed and doesn't reread (I guess probably only if the regex is static, as a regex containing a variable might change; do we need a perl-esque "/o" modifier?) or 2) has working "promise_kept" / "promise_repaired" semantics for variable promises? Is there perhaps value in adding an attribute to a variable like "once => true" to hint that the parser that there's no need to reevaluate an "expensive" variable assignment that I know will be right the first time? Ok, I'm done rambling on this. :) _______________________________________________ Help-cfengine mailing list Help-cfengine@cfengine.org https://cfengine.org/mailman/listinfo/help-cfengine