a_igin

neo4j python slow case

Nov 12th, 2023
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.26 KB | None | 0 0
  1. @app.command(name="test_catalog_request")
  2. def test_catalog_request() -> None:
  3.     """."""
  4.     from neo4j import GraphDatabase
  5.     import time
  6.     config = Container.config
  7.     neo4j_url = Container.neo4j_url
  8.     print(neo4j_url)  # neo4j://neo4j_live:7687
  9.  
  10.     auth = (config.neo4j.username(), config.neo4j.password())
  11.  
  12.     driver = GraphDatabase.driver(
  13.         neo4j_url,
  14.         auth=auth,
  15.         database="neo4j",
  16.     )
  17.     full_text = """      
  18.         match (owner:User) - [:USER_CATALOGS] -> (catalog:Catalog)    
  19.         where ID(catalog)=$catalog_id  
  20.         return catalog
  21.    """
  22.     parameters = {'catalog_id': 1}
  23.  
  24.     t_start = time.monotonic()
  25.     response = driver.execute_query(query_=full_text, parameters_=parameters)
  26.     t_end = time.monotonic()
  27.  
  28.     print(response)
  29.     '''
  30.    EagerResult(records=[<Record catalog=<Node element_id='1' labels=frozenset({'Catalog'})
  31.    properties={'is_public': 'true', 'description': 'My description',
  32.    'title': 'My Title'}>>],
  33.    summary=<neo4j._work.summary.ResultSummary object at 0x7fe59f232440>,
  34.    keys=['catalog'])
  35.    '''
  36.     time_diff = round(t_end - t_start, 3)
  37.     print(f"Neo4j: Execute and return time: {time_diff} seconds") Neo4j: Execute and return time: 1.219 seconds
Advertisement
Add Comment
Please, Sign In to add comment