feat(trash): exclude trashed rows from notes + knowledge read paths
This commit is contained in:
@@ -108,7 +108,9 @@ async def create_note(
|
||||
async def get_note(user_id: int, note_id: int) -> Note | None:
|
||||
async with async_session() as session:
|
||||
result = await session.execute(
|
||||
select(Note).where(Note.id == note_id, Note.user_id == user_id)
|
||||
select(Note).where(
|
||||
Note.id == note_id, Note.user_id == user_id, Note.deleted_at.is_(None)
|
||||
)
|
||||
)
|
||||
return result.scalars().first()
|
||||
|
||||
@@ -135,8 +137,10 @@ async def list_notes(
|
||||
offset: int = 0,
|
||||
) -> tuple[list[Note], int]:
|
||||
async with async_session() as session:
|
||||
query = select(Note).where(Note.user_id == user_id)
|
||||
count_query = select(func.count(Note.id)).where(Note.user_id == user_id)
|
||||
query = select(Note).where(Note.user_id == user_id, Note.deleted_at.is_(None))
|
||||
count_query = select(func.count(Note.id)).where(
|
||||
Note.user_id == user_id, Note.deleted_at.is_(None)
|
||||
)
|
||||
|
||||
# Filter by task vs note
|
||||
if is_task is True:
|
||||
@@ -239,6 +243,7 @@ async def get_note_by_title(user_id: int, title: str) -> Note | None:
|
||||
select(Note).where(
|
||||
Note.user_id == user_id,
|
||||
func.lower(Note.title) == func.lower(title.strip()),
|
||||
Note.deleted_at.is_(None),
|
||||
).limit(1)
|
||||
)
|
||||
return result.scalars().first()
|
||||
@@ -402,7 +407,9 @@ async def search_notes_for_context(
|
||||
pattern = f"%{escaped}%"
|
||||
keyword_filters.append(or_(Note.title.ilike(pattern), Note.body.ilike(pattern)))
|
||||
|
||||
query = select(Note).where(Note.user_id == user_id, or_(*keyword_filters))
|
||||
query = select(Note).where(
|
||||
Note.user_id == user_id, or_(*keyword_filters), Note.deleted_at.is_(None)
|
||||
)
|
||||
if orphan_only:
|
||||
query = query.where(Note.project_id.is_(None))
|
||||
elif project_id is not None:
|
||||
@@ -421,7 +428,9 @@ async def get_notes_by_ids(user_id: int, note_ids: list[int]) -> dict[int, Note]
|
||||
return {}
|
||||
async with async_session() as session:
|
||||
result = await session.execute(
|
||||
select(Note).where(Note.user_id == user_id, Note.id.in_(note_ids))
|
||||
select(Note).where(
|
||||
Note.user_id == user_id, Note.id.in_(note_ids), Note.deleted_at.is_(None)
|
||||
)
|
||||
)
|
||||
return {n.id: n for n in result.scalars().all()}
|
||||
|
||||
@@ -444,6 +453,7 @@ async def get_backlinks(user_id: int, note_id: int) -> list[dict]:
|
||||
select(Note.id, Note.title, Note.status).where(
|
||||
Note.user_id == user_id,
|
||||
Note.id != note_id,
|
||||
Note.deleted_at.is_(None),
|
||||
or_(Note.body.like(pattern), Note.body.like(pattern_alias)),
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user