Permalink
Browse files

Don't do initial transaction if journal already has stored entries

  • Loading branch information...
1 parent 33fae70 commit 471c3c14008959e13080e27c464317b8e2dfe1ac @bergie bergie committed Mar 2, 2014
Showing with 16 additions and 12 deletions.
  1. +16 −12 src/lib/Journal.coffee
View
@@ -90,18 +90,22 @@ class Journal extends EventEmitter
@entries = []
@subscribed = true
@store = store || new MemoryJournalStore @graph
- @currentRevision = -1
-
- # Sync journal with current graph
- @startTransaction 'initial', metadata
- @appendCommand 'addNode', node for node in @graph.nodes
- @appendCommand 'addEdge', edge for edge in @graph.edges
- @appendCommand 'addInitial', iip for iip in @graph.initializers
- @appendCommand 'changeProperties', @graph.properties, {} if Object.keys(@graph.properties).length > 0
- @appendCommand 'addInport', {name: k, port: v} for k,v of @graph.inports
- @appendCommand 'addOutport', {name: k, port: v} for k,v of @graph.outports
- @appendCommand 'addGroup', group for group in @graph.groups
- @endTransaction 'initial', metadata
+
+ if @store.transactions.length is 0
+ # Sync journal with current graph to start transaction history
+ @currentRevision = -1
+ @startTransaction 'initial', metadata
+ @appendCommand 'addNode', node for node in @graph.nodes
+ @appendCommand 'addEdge', edge for edge in @graph.edges
+ @appendCommand 'addInitial', iip for iip in @graph.initializers
+ @appendCommand 'changeProperties', @graph.properties, {} if Object.keys(@graph.properties).length > 0
+ @appendCommand 'addInport', {name: k, port: v} for k,v of @graph.inports
+ @appendCommand 'addOutport', {name: k, port: v} for k,v of @graph.outports
+ @appendCommand 'addGroup', group for group in @graph.groups
+ @endTransaction 'initial', metadata
+ else
+ # Persistent store, start with its latest rev
+ @currentRevision = @store.lastRevision
# Subscribe to graph changes
@graph.on 'addNode', (node) =>

0 comments on commit 471c3c1

Please sign in to comment.