Skip to content

Commit

Permalink
Don't do initial transaction if journal already has stored entries
Browse files Browse the repository at this point in the history
  • Loading branch information
bergie committed Mar 2, 2014
1 parent 33fae70 commit 471c3c1
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/lib/Journal.coffee
Expand Up @@ -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) =>
Expand Down

0 comments on commit 471c3c1

Please sign in to comment.