lib/xamplr/persister.rb in xamplr-1.9.12 vs lib/xamplr/persister.rb in xamplr-1.9.13
- old
+ new
@@ -11,11 +11,12 @@
:write_count, :total_write_count,
:total_sync_count, :total_rollback_count,
:cache_hits, :total_cache_hits,
:last_write_count,
:rolled_back,
- :expunged
+ :expunged,
+ :slow_sync
attr_reader :syncing, :format
def initialize(name=nil, format=nil)
@name = name
@format = format
@@ -32,10 +33,11 @@
@last_cache_hits = 0
@total_sync_count = 0
@total_rollback_count = 0
@rolled_back = false
@syncing = false
+ @slow_sync = 0.25
@busy_count = 0
end
def optimise(opts)
@@ -130,16 +132,18 @@
end
def represent(xampl, mentions=[])
#puts "REPRESENT #{xampl} load needed: #{xampl.load_needed}"
# return nil if xampl.load_needed
+ rep = nil
case xampl.default_persister_format || @format
when nil, :xml_format then
- return xampl.persist("", mentions)
+ rep = xampl.persist("", mentions)
when :ruby_format then
- return xampl.to_ruby(mentions)
+ rep = xampl.to_ruby(mentions)
end
+ return rep
rescue => e
msg = "Failed to represent #{ xampl } due to: #{ e }"
puts msg
puts e.backtrace
raise msg
@@ -147,15 +151,19 @@
def realise(representation, target=nil)
# Normally we'd expect to see the representation in the @format format, but
# that isn't necessarily the case. Try to work out what the format might be...
+ #TODO -- this is a bit brutal, but it should work (it is the rule is that this is supposed to be UTF-8)
+ representation_fixed = representation.encode('UTF-8', :invalid => :replace, :undef => :replace)
+# puts "#{ ::File.basename __FILE__ }:#{ __LINE__ } [#{__method__}] ENCODING: #{ representation.encoding } -> #{ representation_fixed.encoding }"
+
xampl = nil
- if representation =~ /^</ then
- xampl = XamplObject.realise_from_xml_string(representation, target)
+ if representation_fixed =~ /^</ then
+ xampl = XamplObject.realise_from_xml_string(representation_fixed, target)
else
- xampl = XamplObject.from_ruby(representation, target)
+ xampl = XamplObject.from_ruby(representation_fixed, target)
end
return xampl.note_realised
end
def write(xampl)
@@ -216,11 +224,11 @@
return xampl
end
def put_changed(msg="")
puts "Changed::#{msg}:"
- @changed.each { | xampl, ignore | puts " #{xampl.tag} #{xampl.get_the_index}" }
+ @changed.each { |xampl, ignore| puts " #{xampl.tag} #{xampl.get_the_index}" }
end
def start_sync_write
#only if needed
end
@@ -266,12 +274,12 @@
done_sync_write
@syncing = false
end
duration = Time.now - duration
- if 0.25 < duration.to_f then
+ if @slow_sync < duration.to_f then
puts "#{ __FILE__ }:#{ __LINE__ } [#{__method__}] SLOW SYNC(#{ duration.to_f }s), changed: #{ @changed.size }"
- @changed.each do | key, value |
+ @changed.each do |key, value|
puts " key: #{ key.class.name }, pid: #{ key.get_the_index }"
end
end
end