Item10560: SetVariablePlugin makes saves painfully slow

pencil
Priority: Normal
Current State: Closed
Released In: n/a
Target Release: n/a
Applies To: Extension
Component: SetVariablePlugin
Branches: trunk
Reported By: PaulHarvey
Waiting For:
Last Change By: MichaelDaum
There are multiple calls to expandCommonVariables, which makes the save needlessly slow. Every macro in the topic text is expanded on save.

In the end I made the following quick hack.

diff --git a/lib/Foswiki/Plugins/SetVariablePlugin/Core.pm b/lib/Foswiki/Plugins/SetVariablePlugin/Core.pm
index 396eb75..084713e 100644
--- a/lib/Foswiki/Plugins/SetVariablePlugin/Core.pm
+++ b/lib/Foswiki/Plugins/SetVariablePlugin/Core.pm
@@ -253,6 +253,8 @@ sub handleBeforeSave {
   $this->{_insideBeforeSaveHandler} = 1;
   writeDebug("handleBeforeSave($web.$topic)");
 
+  # Disable all macros in the text... we only care about GETVAR/SETVAR/etc
+  $text =~ s/%((?!(META:|GETVAR|SETVAR|UNSETVAR))$Foswiki::regex{tagNameRegex}({.*?})?)%/%<nop>$1%/gms;
   # get the rules NOW
   $text = Foswiki::Func::expandCommonVariables($text, $topic, $web);

-- PaulHarvey - 29 Mar 2011

Not a good idea: macros can create SETVARs, as well as VIEW_TEMPLATES ... which the next release will support. Have you got a way to repro a slow save?

-- MichaelDaum - 30 Mar 2011

The saves are about as long as it takes for the view - except that if you're dating DBCache, Solr indexes etc. it can take an extra second or two.

In the extreme case, I've had users create SEARCHes that never complete, and the save script times-out (they are unable to save their work).

-- PaulHarvey - 30 Mar 2011

Simplified the patch.

-- PaulHarvey - 02 Aug 2011

That's no solution. GETVAR/SETVAR/UNSETVARs can materialize using INCLUDE or SEARCH or whatever.

Users that create SEARCHes that never complete ... well shoot em.

-- MichaelDaum - 28 Sep 2011

The problem is that somehow, during a save cycle, the SEARCHes aren't working as designed. Perhaps there's some URLPARAM in the SEARCH that isn't set properly.

Anyway, a terrible update to an ugly hack is at github.

-- PaulHarvey - 29 Nov 2011

Working on slow saves...I like your above patch more than the one on github. It seems to be the right thing to do. One nagging question: can we expand all INCLUDEs only before disabling the rest of the macros? And btw why is %META: part of the exclude list?

-- MichaelDaum - 02 Dec 2011

Added your patch to the latest release (2.01)

-- MichaelDaum - 02 Dec 2011
 
Topic revision: r12 - 02 Dec 2011, MichaelDaum
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy