Skip to content

Commit

Permalink
feat: Improve parser performance (#318)
Browse files Browse the repository at this point in the history
* refactor: mark private function with _

* refactor(parser): add type annotations and clean up code

* chore: use context manager to close session in tests

* chore: update neo4j and Makefile

* refactor: create parser specific directory

* refactor: start taxonomy_parser by copying parser file

* refactor: move logger to separate file

* refactor: remove unnecessary code for taxonomy parser

* feat: update TaxonomyParser to return taxonomy class

* feat: update parser to use taxonomy parser

* chore: update tests for new taxonomy parser

* fix: remove multi_label for single project_label

* feat: improve node creation performance

* feat: add node id index to improve search query performance

* feat: improve previous link creation performance

* feat: improve child link creation performance

* feat: group queries into transaction

* chore: update logging info and add timing info

* fix: add db name to sessions

* refactor: move ellipsis func to logger class

* fix: stop id index creation if index exists

* fix: resolve comments

* fix: resolve comments
  • Loading branch information
eric-nguyen-cs authored Jan 17, 2024
1 parent 71b34be commit 78fdffc
Show file tree
Hide file tree
Showing 4 changed files with 247 additions and 145 deletions.
5 changes: 3 additions & 2 deletions backend/editor/graph_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from .exceptions import TransactionMissingError

log = logging.getLogger(__name__)
DEFAULT_DB = "neo4j"


txn = contextvars.ContextVar("txn")
Expand All @@ -29,7 +30,7 @@ async def TransactionCtx():
"""
global txn, session
try:
async with driver.session() as _session:
async with driver.session(database=DEFAULT_DB) as _session:
txn_manager = await _session.begin_transaction()
async with txn_manager as _txn:
txn.set(_txn)
Expand Down Expand Up @@ -86,5 +87,5 @@ def SyncTransactionCtx():
"""
uri = settings.uri
driver = neo4j.GraphDatabase.driver(uri)
with driver.session() as _session:
with driver.session(database=DEFAULT_DB) as _session:
yield _session
5 changes: 5 additions & 0 deletions parser/openfoodfacts_taxonomy_parser/parser/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@


class ParserConsoleLogger:
@staticmethod
def ellipsis(text, max=20):
"""Cut a text adding eventual ellipsis if we do not display it fully"""
return text[:max] + ("..." if len(text) > max else "")

def __init__(self):
self.parsing_warnings = [] # Stores all warning logs
self.parsing_errors = [] # Stores all error logs
Expand Down
Loading

0 comments on commit 78fdffc

Please sign in to comment.