修复刷新页面索引时的逻辑错误

master
落雨楓 2 years ago
parent 50bab7b669
commit 6e0a21d84a

@ -14,7 +14,7 @@ class TitleCollectionModel(BaseModel):
page_id: Mapped[int] = mapped_column(sqlalchemy.Integer, index=True, nullable=True) page_id: Mapped[int] = mapped_column(sqlalchemy.Integer, index=True, nullable=True)
class TitleCollectionHelper(BaseHelper): class TitleCollectionHelper(BaseHelper):
async def add(self, title: str, page_id: Optional[int] = None) -> Union[int, bool]: async def add(self, title: str, page_id: Optional[int] = None) -> TitleCollectionModel | None:
stmt = select(TitleCollectionModel.id).where(TitleCollectionModel.title == title) stmt = select(TitleCollectionModel.id).where(TitleCollectionModel.title == title)
result = await self.session.scalar(stmt) result = await self.session.scalar(stmt)

@ -1,4 +1,5 @@
import asyncio import asyncio
import sys
import base as _ import base as _
import local import local
from service.database import DatabaseService from service.database import DatabaseService
@ -10,9 +11,12 @@ async def main():
dbs = await DatabaseService.create() dbs = await DatabaseService.create()
mw_api = MediaWikiApi.create() mw_api = MediaWikiApi.create()
start_title = sys.argv[1] if len(sys.argv) > 1 else None
continue_key = None continue_key = None
while True: while True:
page_res = await mw_api.get_all_pages(continue_key) page_res = await mw_api.get_all_pages(continue_key, start_title)
start_title = None
title_list = page_res["title_list"] title_list = page_res["title_list"]

@ -160,7 +160,7 @@ class EmbeddingSearchService:
# Collection changed, remove old index # Collection changed, remove old index
if self.collection_id != self.title_index.collection_id: if self.collection_id != self.title_index.collection_id:
async with PageIndexHelper(self.dbs, self.title_index.collection_id) as old_page_index: async with PageIndexHelper(self.dbs, self.title_index.collection_id) as old_page_index:
await self.page_index.init_table() await old_page_index.init_table()
old_page_index.remove_by_page_id(self.page_id) old_page_index.remove_by_page_id(self.page_id)
self.title_index.collection_id = self.collection_id self.title_index.collection_id = self.collection_id

Loading…
Cancel
Save