mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-12-02 11:44:41 +08:00
Perf: more adjustments to scripting
Updating to v1.1.1 Reexecuting script to avoid overhead --HG-- branch : perf extra : rebase_source : 168eaa68ebfeb3c61405dc5151373eed5b774a63
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,5 +1,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Microsoft.Scripting.Hosting;
|
||||||
|
using Orchard.Caching;
|
||||||
using Orchard.Scripting;
|
using Orchard.Scripting;
|
||||||
using Orchard.UI.Widgets;
|
using Orchard.UI.Widgets;
|
||||||
|
|
||||||
@@ -7,31 +9,43 @@ namespace Orchard.Widgets.RuleEngine {
|
|||||||
public class RuleManager : IRuleManager {
|
public class RuleManager : IRuleManager {
|
||||||
private readonly IEnumerable<IRuleProvider> _ruleProviders;
|
private readonly IEnumerable<IRuleProvider> _ruleProviders;
|
||||||
private readonly IScriptingManager _scriptingManager;
|
private readonly IScriptingManager _scriptingManager;
|
||||||
|
private readonly ICacheManager _cacheManager;
|
||||||
|
|
||||||
public RuleManager(IEnumerable<IRuleProvider> ruleProviders, IScriptingManager scriptingManager) {
|
public RuleManager(IEnumerable<IRuleProvider> ruleProviders, IScriptingManager scriptingManager, ICacheManager cacheManager) {
|
||||||
_ruleProviders = ruleProviders;
|
_ruleProviders = ruleProviders;
|
||||||
_scriptingManager = scriptingManager;
|
_scriptingManager = scriptingManager;
|
||||||
|
_cacheManager = cacheManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Matches(string expression) {
|
public bool Matches(string expression) {
|
||||||
object execContextType = _scriptingManager.ExecuteExpression(@"
|
object execContextType = _cacheManager.Get("---", ctx => (object)_scriptingManager.ExecuteExpression(@"
|
||||||
class ExecContext
|
class ExecBlock
|
||||||
def execute(callbacks, text)
|
def initialize(callbacks)
|
||||||
@callbacks = callbacks;
|
@callbacks = callbacks
|
||||||
temp = instance_eval(text.to_s);
|
end
|
||||||
@callbacks = 0;
|
def method_missing(name, *args, &block)
|
||||||
return temp;
|
@callbacks.send(name, args, &block);
|
||||||
end
|
end
|
||||||
|
end
|
||||||
def method_missing(name, *args, &block)
|
class ExecContext
|
||||||
@callbacks.send(name, args, &block);
|
class << self
|
||||||
end
|
def alloc(thing)
|
||||||
end
|
instance_eval 'self.new {' + thing + '}'
|
||||||
ExecContext
|
end
|
||||||
");
|
end
|
||||||
|
def initialize(&block)
|
||||||
object execContext = _scriptingManager.ExecuteOperation(ops => ops.CreateInstance(execContextType));
|
@block = block
|
||||||
return _scriptingManager.ExecuteOperation(ops => ops.InvokeMember(execContext, "execute", new CallbackApi(this), expression));
|
end
|
||||||
|
def evaluate(callbacks)
|
||||||
|
ExecBlock.new(callbacks).instance_eval(&@block)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
ExecContext
|
||||||
|
"));
|
||||||
|
var ops = _cacheManager.Get("----", ctx => (ObjectOperations)_scriptingManager.ExecuteOperation(x => x));
|
||||||
|
object execContext = _cacheManager.Get(expression, ctx => (object)ops.InvokeMember(execContextType, "alloc", expression));
|
||||||
|
dynamic result = ops.InvokeMember(execContext, "evaluate", new CallbackApi(this));
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class CallbackApi {
|
public class CallbackApi {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ namespace Orchard.Scripting {
|
|||||||
public ScriptingManager(IScriptingRuntime scriptingRuntime) {
|
public ScriptingManager(IScriptingRuntime scriptingRuntime) {
|
||||||
_scriptingRuntime = scriptingRuntime;
|
_scriptingRuntime = scriptingRuntime;
|
||||||
_scope = new Lazy<ScriptScope>(()=>_scriptingRuntime.CreateScope());
|
_scope = new Lazy<ScriptScope>(()=>_scriptingRuntime.CreateScope());
|
||||||
_operations = new Lazy<ObjectOperations>(()=>_scope.Value.Engine.CreateOperations());
|
_operations = new Lazy<ObjectOperations>(()=>_scope.Value.Engine.Operations);
|
||||||
}
|
}
|
||||||
|
|
||||||
public dynamic GetVariable(string name) {
|
public dynamic GetVariable(string name) {
|
||||||
|
|||||||
Reference in New Issue
Block a user