Is py2neo caching burning me?

与世无争的帅哥 提交于 2019-12-24 11:45:14

问题


I am running this code:

c = """
    match(r:XX)
    optional match(r)-[]-(m) with count(m) as mc, r match(x)
    return count(x) as all, r, mc
    """
        (snip!)
        while(True):
            tx = remote_graph.cypher.begin()
            res = remote_graph.cypher.execute(c)
            tx.rollback()
            time.sleep(15)
        (snip!)

I know for a fact the XX node's properties are changing every second - there a daemon running. However, when I run this, I always get the same values back in res but for r only - all is changing. The query isn't changing. I wonder if py2neo is noticing this and not executing the query, but is returning me a cached copy? If so, how do I stop this from happening?

EDIT - more info - I ran the above from within ipython.


回答1:


Interesting enough, py2neo 'remembers' the node when you return the node:

MATCH (n:Node) RETURN n

But when you return individual properties, they will always be updated:

MATCH (n:Node) RETURN n.value

For your query that means you have to run my_node.pull() when you return the same node twice in a while loop:

while True:
    q = "MATCH (n:Node) RETURN n"
    result = graph.cypher.execute(q)
    my_node = result[0][0]
    my_node.pull()
    print(my_node)

You can also move everything besides the pull() out of the loop:

q = "MATCH (n:Node) RETURN n"
result = graph.cypher.execute(q)
my_node = result[0][0]

while True:
    my_node.pull()
    print(my_node)

Here is a minimal example describing the behaviour: http://paste.ubuntu.com/14015568/

I'm not really sure why py2neo does not return updated node data when you run a new query.




回答2:


What do you mean when you say the node's attributes? Do you mean properties? Or are relationships added/removed as well?

What do you expect to get back in r? Judging from the query, unless the daemon you mention is adding/removing the :XX label to/from nodes, it'll return exactly the same nodes always.



来源:https://stackoverflow.com/questions/34273072/is-py2neo-caching-burning-me

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!