Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

various optimazations

  • Loading branch information...
commit 235f792745f57b1da232bb5636c39a72621e70c2 1 parent ca6ef27
@kmees kmees authored
View
22 src/IronSharePoint.IronRuby10/IronSharePoint.IronRuby10.sln
@@ -0,0 +1,22 @@
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IronSharePoint.IronRuby10", "IronSharePoint.IronRuby10.csproj", "{6E073DFC-A506-44DF-B378-7C539ED71502}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {6E073DFC-A506-44DF-B378-7C539ED71502}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {6E073DFC-A506-44DF-B378-7C539ED71502}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {6E073DFC-A506-44DF-B378-7C539ED71502}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
+ {6E073DFC-A506-44DF-B378-7C539ED71502}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {6E073DFC-A506-44DF-B378-7C539ED71502}.Release|Any CPU.Build.0 = Release|Any CPU
+ {6E073DFC-A506-44DF-B378-7C539ED71502}.Release|Any CPU.Deploy.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
View
4 src/IronSharePoint/IronConsole/Hooks/RubyConsoleHook.cs
@@ -9,6 +9,7 @@ class RubyConsoleHook : IronConsoleHookBase
public override void BeforeExecute(ScriptEngine scriptEngine, IronConsoleResult result)
{
base.BeforeExecute(scriptEngine, result);
+ /*
scriptEngine.Execute(
@"
unless respond_to? :out
@@ -18,12 +19,13 @@ public override void BeforeExecute(ScriptEngine scriptEngine, IronConsoleResult
#raise 'Could not load console utils'
end
end");
+ */
}
public override void AfterExecute(ScriptEngine scriptEngine, IronConsoleResult result)
{
base.AfterExecute(scriptEngine, result);
- var consoleOut = scriptEngine.Execute(String.Format("out '{0}'", Environment.NewLine));
+ var consoleOut = scriptEngine.Execute(String.Format("out '{0}' if respond_to? :out", Environment.NewLine));
result.Output = Convert.ToString(consoleOut);
result.Result = result.Result ?? "nil";
}
View
57 src/IronSharePoint/IronRuntime.cs
@@ -186,40 +186,53 @@ private void PrivilegedInitialize(string rubyRoot)
public static IronRuntime GetDefaultIronRuntime(SPSite targetSite)
{
- using (new SPMonitoredScope("Retrieving IronRuntime"))
+ const string RuntimeKey = "IronSP_Runtime";
+ IronRuntime runtime = null;
+ if (HttpContext.Current != null && HttpContext.Current.Items.Contains(RuntimeKey))
{
- Guid hiveId = IronHiveRegistry.Local.GetHiveForSite(targetSite.ID);
- if (hiveId == Guid.Empty)
- {
- throw new InvalidOperationException(
- String.Format("There is no IronHive mapping for the site with id {0}", targetSite.ID));
- }
+ runtime = HttpContext.Current.Items[RuntimeKey] as IronRuntime;
+ }
- IronRuntime runtime;
- if (!LivingRuntimes.ContainsKey(hiveId))
+ if (runtime == null)
+ {
+ using (new SPMonitoredScope("Retrieving IronRuntime"))
{
- lock (_sync)
+ Guid hiveId = IronHiveRegistry.Local.GetHiveForSite(targetSite.ID);
+ if (hiveId == Guid.Empty)
{
- if (!LivingRuntimes.TryGetValue(hiveId, out runtime))
+ throw new InvalidOperationException(
+ String.Format("There is no IronHive mapping for the site with id {0}", targetSite.ID));
+ }
+
+ if (!LivingRuntimes.ContainsKey(hiveId))
+ {
+ lock (_sync)
{
- using (new SPMonitoredScope("Creating IronRuntime"))
+ if (!LivingRuntimes.TryGetValue(hiveId, out runtime))
{
- runtime = new IronRuntime(hiveId);
- LivingRuntimes[hiveId] = runtime;
- runtime.Initialize();
+ using (new SPMonitoredScope("Creating IronRuntime"))
+ {
+ runtime = new IronRuntime(hiveId);
+ LivingRuntimes[hiveId] = runtime;
+ runtime.Initialize();
+ }
}
}
}
+ runtime = LivingRuntimes[hiveId];
+ if (HttpContext.Current != null)
+ {
+ HttpContext.Current.Items[RuntimeKey] = runtime;
+ }
}
- runtime = LivingRuntimes[hiveId];
-
- if (!runtime.IsInitialized)
- {
- ShowUnavailable();
- }
+ }
- return runtime;
+ if (!runtime.IsInitialized)
+ {
+ ShowUnavailable();
}
+
+ return runtime;
}
public IronEngine GetEngineByExtension(string extension)
View
2  src/IronSharePoint/IronSharePoint.csproj
@@ -231,6 +231,8 @@
<None Include="TEMPLATE\Features\IronSP_Root\iron_sharepoint\mixins\control_view.rb" />
<None Include="TEMPLATE\Features\IronSP_Root\iron_sharepoint\mixins\logging.rb" />
<None Include="TEMPLATE\Features\IronSP_Root\iron_sharepoint\mixins\parent_attributes.rb" />
+ <None Include="TEMPLATE\Features\IronSP_Root\iron_sharepoint\mixins\short_term_memory.rb" />
+ <None Include="TEMPLATE\Features\IronSP_Root\iron_sharepoint\mixins\sp_context_accessors.rb" />
<None Include="TEMPLATE\Features\IronSP_Root\iron_sharepoint\mixins\type_registration.rb" />
<None Include="TEMPLATE\Features\IronSP_Root\iron_sharepoint\mixins\view_helpers.rb" />
<None Include="TEMPLATE\Features\IronSP_Root\iron_sharepoint\object.rb" />
View
3  src/IronSharePoint/TEMPLATE/Features/IronSP_Root/iron_sharepoint/console/utils.rb
@@ -62,3 +62,6 @@ def out_buffer
end
end
end
+
+include IronSharePoint::Console::Utils
+puts self
View
3  src/IronSharePoint/TEMPLATE/Features/IronSP_Root/iron_sharepoint/iron_composite_control.rb
@@ -2,12 +2,14 @@
require 'iron_sharepoint/mixins/type_registration'
require 'iron_sharepoint/mixins/control_view'
require 'iron_sharepoint/mixins/parent_attributes'
+require 'iron_sharepoint/mixins/short_term_memory'
module IronSharePoint
class IronCompositeControl
include Mixins::Logging
include Mixins::ControlView
include Mixins::ParentAttributes
+ extend Mixins::ShortTermMemory
def self.inherited child
child.send :include, Mixins::TypeRegistration
@@ -17,6 +19,7 @@ def CreateChildControls
monitor "Render #{self.class.name}" do
begin
unless self.page.nil?
+ self.view.context = view_context
ctrl = self.page.parse_control(self.view.render)
self.controls.add(ctrl)
end
View
1  src/IronSharePoint/TEMPLATE/Features/IronSP_Root/iron_sharepoint/iron_control.rb
@@ -17,6 +17,7 @@ def self.inherited child
def Render(writer)
monitor "Render #{self.class.name}" do
+ self.view.context = view_context
writer.Write self.view.render
end
end
View
2  src/IronSharePoint/TEMPLATE/Features/IronSP_Root/iron_sharepoint/iron_view.rb
@@ -43,7 +43,7 @@ def render
rescue Exception => ex
logger.error ex if respond_to? :logger
if (SPContext.current && SPContext.current.web.current_user)
- compiled_template("template_error.haml").render :message => ex.message, :backtrace => ex.backtrace
+ compiled_template("template_error.haml").render(self, {:message => ex.message, :backtrace => ex.backtrace})
else
""
end
View
1  src/IronSharePoint/TEMPLATE/Features/IronSP_Root/iron_sharepoint/mixins/control_view.rb
@@ -42,7 +42,6 @@ def template
def view
@view ||= IronSharePoint::IronView.new({
:template => template,
- :context => view_context,
:parent => self
})
end
View
119 src/IronSharePoint/TEMPLATE/Features/IronSP_Root/iron_sharepoint/mixins/short_term_memory.rb
@@ -39,53 +39,103 @@ def flush_cache(*syms)
syms.each do |sym|
(methods + private_methods + protected_methods).each do |m|
if m.to_s =~ /^_unremembered_(#{sym.to_s.gsub(/\?\Z/, '\?')})/
- cache_key = cache_key_for $1
- invalidate cache_key
+ [true, false].each do |b|
+ cache_key = cache_key_for $1, b
+ invalidate cache_key
+ end
end
end
end
end
- def remember(*symbols)
+ def cremember(*symbols)
symbols.each do |symbol|
original_method = :"_unremembered_#{symbol}"
- cache_key = cache_key_for symbol
- class_eval <<-EOS, __FILE__, __LINE__ + 1
- if method_defined?(:#{original_method})
- raise "Already remembered #{symbol}"
- end
- alias #{original_method} #{symbol}
-
- if instance_method(:#{symbol}).arity == 0
- def #{symbol}(reload = false)
- result = self.class.fetch '#{cache_key}'
- if reload || result.nil?
- result = #{original_method}
- self.class.store '#{cache_key}', result
+ instance_eval <<-EOS, __FILE__, __LINE__ + 1
+ if !methods.include?('#{original_method}')
+ alias #{original_method} #{symbol}
+
+ if method(:#{symbol}).arity == 0
+ def #{symbol}(reload = false)
+ cache_key = self.cache_key_for :#{symbol}, true
+ result = self.fetch cache_key
+ if reload || result.nil?
+ result = #{original_method}
+ self.store cache_key, result
+ end
+ return result
+ end
+ else
+ def #{symbol}(*args)
+ cache_key = self.cache_key_for :#{symbol}, true
+ args_length = method(:#{original_method}).arity
+ if args.length == args_length + 1 &&
+ (args.last == true || args.last == :reload)
+ reload = args.pop
+ end
+
+ result = self.fetch cache_key, args
+ if reload || result.nil?
+ result = #{original_method}(*args)
+ self.store cache_key, result, args
+ end
+ return result
+ end
end
- return result
end
- else
- def #{symbol}(*args)
- args_length = method(:#{original_method}).arity
- if args.length == args_length + 1 &&
- (args.last == true || args.last == :reload)
- reload = args.pop
- end
+ EOS
+ end
+ end
+
+ def remember(*symbols)
+ symbols.each do |symbol|
+ original_method = :"_unremembered_#{symbol}"
- result = self.class.fetch '#{cache_key}', args
- if reload || result.nil?
- result = #{original_method}(*args)
- self.class.store '#{cache_key}', result, args
+ class_eval <<-EOS, __FILE__, __LINE__ + 1
+ if !method_defined?(:#{original_method})
+ alias #{original_method} #{symbol}
+
+ if instance_method(:#{symbol}).arity == 0
+ def #{symbol}(reload = false)
+ cache_key = self.class.cache_key_for :#{symbol}, true
+ result = self.class.fetch cache_key
+ if reload || result.nil?
+ result = #{original_method}
+ self.class.store cache_key, result
+ end
+ return result
+ end
+ else
+ def #{symbol}(*args)
+ cache_key = self.class.cache_key_for :#{symbol}, true
+ args_length = method(:#{original_method}).arity
+ if args.length == args_length + 1 &&
+ (args.last == true || args.last == :reload)
+ reload = args.pop
+ end
+
+ result = self.class.fetch cache_key, args
+ if reload || result.nil?
+ result = #{original_method}(*args)
+ self.class.store cache_key, result, args
+ end
+ return result
+ end
end
- return result
end
- end
- EOS
+ EOS
end
end
+ def cache_key_for symbol, instance = false
+ variation = IronSharePoint::Variation.current
+ class_name = self.is_a?(Module) ? self.name : self.class.name
+ seperator = instance ? "#" : "."
+
+ "#{variation}_#{class_name}#{seperator}#{symbol}"
+ end
+
def store key, data, args = []
if http_cache
hash = http_cache[key] || {}
@@ -123,13 +173,6 @@ def must_cache?
!cache_settings.fetch(:anonymous_only, true) || SPContext.current.web.current_user.nil?
end
- def cache_key_for symbol
- variation = IronSharePoint::Variation.current
- class_name = self.is_a?(Class) ? self.name : self.class.name
-
- "#{variation}_#{class_name}##{symbol}"
- end
-
def http_cache
if http_context && must_cache?
http_context.cache
View
21 ...onSharePoint/TEMPLATE/Features/IronSP_Root/iron_sharepoint/mixins/sp_context_accessors.rb
@@ -0,0 +1,21 @@
+module IronSharePoint::Mixins
+ module SPContextAccessors
+ attr_writer :current_web, :current_item, :current_list, :current_site
+
+ def current_web
+ @current_web || (SPContext.current.web unless SPContext.current.nil?)
+ end
+
+ def current_item
+ @current_item || (SPContext.current.item unless SPContext.current.nil?)
+ end
+
+ def current_site
+ @current_site || (SPContext.current.site unless SPContext.current.nil?)
+ end
+
+ def current_list
+ @current_list || (SPContext.current.list unless SPContext.current.nil?)
+ end
+ end
+end
View
1  ...IronSharePoint/TEMPLATE/Features/IronSP_Root/iron_sharepoint/patches/i18n/backend/base.rb
@@ -1,4 +1,5 @@
require 'iron_sharepoint/patches/core/string'
+require 'i18n/backend/base'
module I18n
module Backend
Please sign in to comment.
Something went wrong with that request. Please try again.