Skip to content

Commit

Permalink
refresh session
Browse files Browse the repository at this point in the history
  • Loading branch information
mruwnik committed Dec 17, 2023
1 parent 8de159f commit adc6d26
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
6 changes: 3 additions & 3 deletions align_data/common/alignment_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ def commit() -> bool:
session.rollback()
return False

with make_session() as session:
items = iter(entries)
while batch := tuple(islice(items, self.batch_size)):
items = iter(entries)
while batch := tuple(islice(items, self.batch_size)):
with make_session() as session:
self._add_batch(session, batch)
# there might be duplicates in the batch, so if they cause
# an exception, try to commit them one by one
Expand Down
15 changes: 8 additions & 7 deletions align_data/db/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
logger = logging.getLogger(__name__)

# We create a single engine for the entire application
engine = create_engine(DB_CONNECTION_URI, echo=False)
engine = create_engine(DB_CONNECTION_URI, echo=False, pool_pre_ping=True)


@contextmanager
Expand All @@ -35,13 +35,12 @@ def get_pinecone_articles(


def get_pinecone_articles_to_remove(session: Session):
return (
session.query(Article)
.filter(or_(
return session.query(Article).filter(
or_(
Article.pinecone_status == PineconeStatus.pending_removal,
Article.is_valid == False,
Article.confidence < MIN_CONFIDENCE
))
Article.confidence < MIN_CONFIDENCE,
)
)


Expand All @@ -51,7 +50,9 @@ def get_pinecone_articles_by_sources(
force_update: bool = False,
statuses: List[PineconeStatus] = [PineconeStatus.pending_addition],
):
return get_pinecone_articles(session, force_update, statuses).filter(Article.source.in_(custom_sources))
return get_pinecone_articles(session, force_update, statuses).filter(
Article.source.in_(custom_sources)
)


def get_pinecone_articles_by_ids(
Expand Down

0 comments on commit adc6d26

Please sign in to comment.