lib/ruote/log/storage_history.rb in ruote-2.1.6 vs lib/ruote/log/storage_history.rb in ruote-2.1.7

- old
+ new

@@ -32,10 +32,12 @@ # HashStorage. It will fill up your memory... Keeping history for a # transient ruote is a bit overkill (IMHO). # class StorageHistory + DATE_REGEX = /!(\d{4}-\d{2}-\d{2})!/ + def initialize (context, options={}) @context = context @options = options @@ -58,21 +60,24 @@ # def range ids = @context.storage.ids('history') - first = Time.parse("#{ids.first.split('!')[0]} 00:00:00 UTC") - last = Time.parse("#{ids.last.split('!')[0]} 00:00:00 UTC") + 24 * 3600 + fm = DATE_REGEX.match(ids.first)[1] + lm = DATE_REGEX.match(ids.last)[1] + first = Time.parse("#{fm} 00:00:00 UTC") + last = Time.parse("#{lm} 00:00:00 UTC") + 24 * 3600 + [ first, last ] end def by_date (date) - date = Time.parse(date.to_s).strftime('%F') + date = Time.parse(date.to_s).strftime('%Y-%m-%d') - @context.storage.get_many('history', /^#{date}!/) + @context.storage.get_many('history', /!#{date}!/) end #def history_to_tree (wfid) # # (NOTE why not ?) #end @@ -99,15 +104,16 @@ Ruote::FlowExpressionId.to_storage_id(fei) else msg['wfid'] || 'no_wfid' end - t = Time.parse(msg['put_at']) + _id = msg['_id'] + msg['original_id'] = _id + msg['_id'] = "#{_id}!#{si}" - msg['original_id'] = msg['_id'] - msg['_id'] = "#{t.strftime('%F')}!#{t.to_i}_#{"%06d" % t.usec}!#{si}" msg['type'] = 'history' msg['original_put_at'] = msg['put_at'] + msg.delete('_rev') @context.storage.put(msg) end end