mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-06 22:12:12 +02:00
fix: run ruff formatter to fix code quality
This commit is contained in:
parent
b98c312fb1
commit
e419702ebd
4 changed files with 77 additions and 66 deletions
|
|
@ -51,12 +51,16 @@ def upgrade() -> None:
|
||||||
|
|
||||||
# Queue the task to run asynchronously
|
# Queue the task to run asynchronously
|
||||||
populate_blocknote_for_documents_task.apply_async()
|
populate_blocknote_for_documents_task.apply_async()
|
||||||
print("✓ Queued Celery task to populate blocknote_document for existing documents")
|
print(
|
||||||
|
"✓ Queued Celery task to populate blocknote_document for existing documents"
|
||||||
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# If Celery is not available or task queueing fails, log but don't fail the migration
|
# If Celery is not available or task queueing fails, log but don't fail the migration
|
||||||
print(f"⚠ Warning: Could not queue blocknote population task: {e}")
|
print(f"⚠ Warning: Could not queue blocknote population task: {e}")
|
||||||
print(" You can manually trigger it later with:")
|
print(" You can manually trigger it later with:")
|
||||||
print(" celery -A app.celery_app call app.tasks.celery_tasks.blocknote_migration_tasks.populate_blocknote_for_documents_task")
|
print(
|
||||||
|
" celery -A app.celery_app call app.tasks.celery_tasks.blocknote_migration_tasks.populate_blocknote_for_documents_task"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def downgrade() -> None:
|
def downgrade() -> None:
|
||||||
|
|
|
||||||
|
|
@ -141,5 +141,5 @@ async def save_document(
|
||||||
"status": "saved",
|
"status": "saved",
|
||||||
"document_id": document_id,
|
"document_id": document_id,
|
||||||
"message": "Document saved and will be reindexed in the background",
|
"message": "Document saved and will be reindexed in the background",
|
||||||
"last_edited_at": document.last_edited_at.isoformat()
|
"last_edited_at": document.last_edited_at.isoformat(),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,9 @@ async def _populate_blocknote_for_documents(
|
||||||
|
|
||||||
for i in range(0, total_documents, batch_size):
|
for i in range(0, total_documents, batch_size):
|
||||||
batch = documents[i : i + batch_size]
|
batch = documents[i : i + batch_size]
|
||||||
logger.info(f"Processing batch {i // batch_size + 1}: documents {i+1}-{min(i+batch_size, total_documents)}")
|
logger.info(
|
||||||
|
f"Processing batch {i // batch_size + 1}: documents {i + 1}-{min(i + batch_size, total_documents)}"
|
||||||
|
)
|
||||||
|
|
||||||
for document in batch:
|
for document in batch:
|
||||||
try:
|
try:
|
||||||
|
|
@ -109,7 +111,9 @@ async def _populate_blocknote_for_documents(
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Reconstruct markdown by concatenating chunk contents
|
# Reconstruct markdown by concatenating chunk contents
|
||||||
markdown_content = "\n\n".join(chunk.content for chunk in chunks)
|
markdown_content = "\n\n".join(
|
||||||
|
chunk.content for chunk in chunks
|
||||||
|
)
|
||||||
|
|
||||||
if not markdown_content or not markdown_content.strip():
|
if not markdown_content or not markdown_content.strip():
|
||||||
logger.warning(
|
logger.warning(
|
||||||
|
|
@ -119,7 +123,9 @@ async def _populate_blocknote_for_documents(
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Convert markdown to BlockNote JSON
|
# Convert markdown to BlockNote JSON
|
||||||
blocknote_json = await convert_markdown_to_blocknote(markdown_content)
|
blocknote_json = await convert_markdown_to_blocknote(
|
||||||
|
markdown_content
|
||||||
|
)
|
||||||
|
|
||||||
if not blocknote_json:
|
if not blocknote_json:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
|
|
@ -136,7 +142,9 @@ async def _populate_blocknote_for_documents(
|
||||||
# Commit every batch_size documents to avoid long transactions
|
# Commit every batch_size documents to avoid long transactions
|
||||||
if processed % batch_size == 0:
|
if processed % batch_size == 0:
|
||||||
await session.commit()
|
await session.commit()
|
||||||
logger.info(f"Committed batch: {processed} documents processed so far")
|
logger.info(
|
||||||
|
f"Committed batch: {processed} documents processed so far"
|
||||||
|
)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(
|
logger.error(
|
||||||
|
|
|
||||||
|
|
@ -84,9 +84,8 @@ async def _reindex_document(document_id: int, user_id: str):
|
||||||
|
|
||||||
# 2. Delete old chunks explicitly
|
# 2. Delete old chunks explicitly
|
||||||
from app.db import Chunk
|
from app.db import Chunk
|
||||||
await session.execute(
|
|
||||||
delete(Chunk).where(Chunk.document_id == document_id)
|
await session.execute(delete(Chunk).where(Chunk.document_id == document_id))
|
||||||
)
|
|
||||||
await session.flush() # Ensure old chunks are deleted
|
await session.flush() # Ensure old chunks are deleted
|
||||||
|
|
||||||
# 3. Create new chunks
|
# 3. Create new chunks
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue