Changeset - 72380e12d86c
[Not reviewed]
default
0 1 0
Drew Perttula - 7 years ago 2018-05-29 07:00:37
drewp@bigasterisk.com
performance: add @cachedUriValues
Ignore-this: f3a707bc25acc028dedd2f115a5d17e5
1 file changed with 10 insertions and 2 deletions:
0 comments (0 inline, 0 general)
light9/web/graph.coffee
Show inline comments
 
@@ -150,13 +150,14 @@ class window.SyncedGraph
 
    if @graph?
 
      @_applyPatch({addQuads: [], delQuads: @graph.getQuads()})
 

	
 
    # if we had a Store already, this lets N3.Store free all its indices/etc
 
    @graph = N3.Store()
 
    @_addPrefixes(@prefixes)
 
    @cachedFloatValues = new Map()
 
    @cachedFloatValues = new Map() # s + '|' + p -> number
 
    @cachedUriValues = new Map() # s + '|' + p -> Uri
 

	
 
  _clearGraphOnNewConnection: -> # must not send a patch to the server!
 
    log('graph: clearGraphOnNewConnection')
 
    @clearGraph()
 
    log('graph: clearGraphOnNewConnection done')
 
      
 
@@ -225,12 +226,13 @@ class window.SyncedGraph
 
    
 
  _applyPatch: (patch) ->
 
    # In most cases you want applyAndSendPatch.
 
    #
 
    # This is the only method that writes to @graph!
 
    @cachedFloatValues.clear()
 
    @cachedUriValues.clear()
 
    for quad in patch.delQuads
 
      #log("remove #{JSON.stringify(quad)}")
 
      did = @graph.removeQuad(quad)
 
      #log("removed: #{did}")
 
    for quad in patch.addQuads
 
      @graph.addQuad(quad)
 
@@ -288,13 +290,19 @@ class window.SyncedGraph
 
    return ret
 
    
 
  stringValue: (s, p) ->
 
    @_singleValue(s, p).value
 
    
 
  uriValue: (s, p) ->
 
    @_singleValue(s, p)
 
    key = s.value + '|' + p.value
 
    hit = @cachedUriValues.get(key)
 
    return hit if hit != undefined
 

	
 
    ret = @_singleValue(s, p)
 
    @cachedUriValues.set(key, ret)
 
    return ret
 

	
 
  labelOrTail: (uri) ->
 
    try
 
      ret = @stringValue(uri, @Uri('rdfs:label'))
 
    catch
 
      words = uri.value.split('/')
0 comments (0 inline, 0 general)