Skip to content

Commit ffead71

Browse files
committed
remove direct db call from ingestion service
1 parent 760eea2 commit ffead71

2 files changed

Lines changed: 5 additions & 9 deletions

File tree

src/infrastructure/db/repository.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from uuid import UUID
22

3-
from sqlalchemy import func, select
3+
from sqlalchemy import func, select, update
44
from sqlalchemy.dialects.postgresql import insert
55
from sqlalchemy.ext.asyncio import AsyncSession
66

@@ -60,9 +60,9 @@ async def upsert_chunk(
6060

6161
@staticmethod
6262
async def update_source_synced(session: AsyncSession, source_id: UUID) -> None:
63-
result = await session.execute(select(SourceRow).where(SourceRow.id == source_id))
64-
source = result.scalar_one()
65-
source.last_synced_at = func.now()
63+
await session.execute(
64+
update(SourceRow).where(SourceRow.id == source_id).values(last_synced_at=func.now())
65+
)
6666

6767
@staticmethod
6868
async def top_k_chunks(

src/ingestion/services/ingestion_service.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import hashlib
22

33
from langchain_text_splitters import RecursiveCharacterTextSplitter
4-
from sqlalchemy import func, update
54

65
from src.config.logger import get_logger
76
from src.infrastructure.db import async_session_factory
8-
from src.infrastructure.db.models import SourceRow
97
from src.infrastructure.db.repository import Repository
108
from src.ingestion.scrapers.html_scraper import scrape
119
from src.retrieval.services import embedding_service
@@ -75,9 +73,7 @@ async def ingest_url(url: str) -> None:
7573
source_id=source.id,
7674
)
7775

78-
await session.execute(
79-
update(SourceRow).where(SourceRow.id == source.id).values(last_synced_at=func.now())
80-
)
76+
await Repository.update_source_synced(session, source.id)
8177
await session.commit()
8278

8379
log.info("ingest_complete", url=url, n_chunks=len(chunks))

0 commit comments

Comments
 (0)