Skip to content

Commit

Permalink
Merge pull request #228 from sarah256/recent-stories
Browse files Browse the repository at this point in the history
Rewrite cypher query so that it goes through each node type individually instead of as one large query
  • Loading branch information
mprahl committed Mar 11, 2019
2 parents 20774e0 + 3e6aba7 commit fdac2c7
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions estuary/utils/recents.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from estuary.models.errata import Advisory
from estuary.models.freshmaker import FreshmakerEvent

from estuary import log
from estuary.utils.general import inflate_node


Expand All @@ -29,21 +28,17 @@ def get_recent_nodes():
Advisory.__label__: 'update_date'
}

query = 'CALL apoc.cypher.runMany(\''
final_result = {}
for label, time_property in label_dict.items():
query += (
'\n MATCH ({label}:{label}) RETURN {label} '
'ORDER BY {label}.{time_property} DESC LIMIT 5;'
query = (
'MATCH (node:{label}) RETURN node '
'ORDER BY node.{time_property} DESC LIMIT 5'
).format(label=label, time_property=time_property)
query = '{0}\'\n, {{}}, {{statistics: False, timeout: 15}});'.format(query)
log.debug('Querying Neo4j with:\n{0}'.format(query))

final_result = {}
results, _ = db.cypher_query(query)
for result in [result[1] for result in results]:
for label, raw_node in result.items():
results, _ = db.cypher_query(query)
for result in results:
node_results = final_result.setdefault(label, [])
node = inflate_node(raw_node)
# result is always a list of a single node
node = inflate_node(result[0])
node_results.append(node.serialized)

return final_result

0 comments on commit fdac2c7

Please sign in to comment.