willzeng / cograph

A way to build and explore webs of ideas.
http://www.cograph.co/
GNU General Public License v2.0
15 stars 3 forks source link

negative expand values #575

Closed willzeng closed 9 years ago

davidfurlong commented 9 years ago

I've isolated the problem to routes/sockets/nodes.coffee, exports.readCollection where nodeData sets the current expand node count to 0 @willzeng I've tried to fix it but I'm not sure how all this code works, can you take a look. I reckon we need to call something like

serverNode.getNeighbors id, (neighbors) -> parsed.neighborCount = neighbors.length socket.emit '/node:read', parsed callback(null, parsed)

willzeng commented 9 years ago

I'm not seeing where the neighborCount of the node is set to zero in this method


exports.readCollection = (data, callback, socket) ->
  console.log "readCollection of nodes in document #{data._docId}"
  docLabel = "_doc_#{data._docId || 0}"
  # SUPER UNSAFE, allows for SQL injection but node-neo4j wasn't interpolating
  cypherQuery = "match (n:#{docLabel}) return n, labels(n);"
  params = {}
  graphDb.query cypherQuery, params, (err, results) ->
    if err then throw err
    parsedNodes = []
    for node in results
      nodeData = node.n._data.data
      nodeData.tags = node['labels(n)']
      parsedNodes.push utils.parseNodeToClient nodeData
    socket.emit '/nodes:read', parsedNodes
    callback null, parsedNodes

I checked the utils method too:


  parseNodeToClient: (serverNode) ->
    serverNode.tags = @parseLabels(serverNode.tags).tags if serverNode.tags
    serverNode

This should just grab whatever the data is saved in the db no? What line do you think is setting it to zero?

davidfurlong commented 9 years ago

Set, pushed and returned. Its part of the node.n._data.data object

nodeData = node.n._data.data

parsedNodes.push utils.parseNodeToClient nodeData

callback null, parsedNodes

willzeng commented 9 years ago

node in results is just whatever is in the neo4j db matching the query. If neighborCount is zero there then that it because it is already zero in the db as the cypherquery is read only.

Does that make sense?

davidfurlong commented 9 years ago

yeah I think the neighbourCount isn't stored in the neo4j but rather calculated on init...

willzeng commented 9 years ago

Hmm let me have more of a look at it later (on the road right now)

willzeng commented 9 years ago

So I have pushed the most recent version of dev to heroku. Can you replicate a negative value using one of the public graphs on there that I can debug on?

davidfurlong commented 9 years ago

Can you replicate a negative value using one of the public graphs on there that I can debug on?

Negative values don't persist. The way to replicate is to create a graph of 3 nodes: connect A to B and B to C. Delete C. B will have a -1 expand #

davidfurlong commented 9 years ago

as in expand values are calculated on load. on refresh the value returns to the correct value. this bug is a problem of us just needing to call the expand number calculation function after the code i highlighted above. i think the function that does it is read, but i couldn't find a fix

willzeng commented 9 years ago

Finally!

On Tue, Nov 4, 2014 at 11:01 AM, David Furlong notifications@github.com wrote:

Closed #575 via #582.

Reply to this email directly or view it on GitHub: https://github.com/willzeng/graphdocs/issues/575#event-188221429