Remove redundant attributes in the file index (#41)

This commit is contained in:
Duc Nguyen (john) 2024-04-20 18:21:32 +07:00 committed by GitHub
parent c6045bcb9f
commit 749c9e5641
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 8 deletions

View File

@ -63,7 +63,6 @@ class FileIndex(BaseIndex):
"relation_type": Column(Integer),
},
)
self._db_tables: dict[str, Any] = {"Source": Source, "Index": Index}
self._vs: BaseVectorStore = get_vectorstore(f"index_{self.id}")
self._docstore: BaseDocumentStore = get_docstore(f"index_{self.id}")
self._fs_path = filestorage_path / f"index_{self.id}"

View File

@ -199,8 +199,8 @@ class FileIndexPage(BasePage):
def delete_yes_event(self, file_id):
with Session(engine) as session:
source = session.execute(
select(self._index._db_tables["Source"]).where(
self._index._db_tables["Source"].id == file_id
select(self._index._resources["Source"]).where(
self._index._resources["Source"].id == file_id
)
).first()
if source:
@ -208,8 +208,8 @@ class FileIndexPage(BasePage):
vs_ids, ds_ids = [], []
index = session.execute(
select(self._index._db_tables["Index"]).where(
self._index._db_tables["Index"].source_id == file_id
select(self._index._resources["Index"]).where(
self._index._resources["Index"].source_id == file_id
)
).all()
for each in index:
@ -431,7 +431,7 @@ class FileIndexPage(BasePage):
return self.index_fn(files, reindex, settings)
def list_file(self):
Source = self._index._db_tables["Source"]
Source = self._index._resources["Source"]
with Session(engine) as session:
statement = select(Source)
results = [
@ -494,7 +494,7 @@ class FileIndexPage(BasePage):
if max_number_of_files := self._index.config.get("max_number_of_files", 0):
with Session(engine) as session:
current_num_files = session.query(
self._index._db_tables["Source"].id
self._index._resources["Source"].id
).count()
if len(paths) + current_num_files > max_number_of_files:
errors.append(
@ -566,7 +566,7 @@ class FileSelector(BasePage):
options = []
available_ids = []
with Session(engine) as session:
statement = select(self._index._db_tables["Source"])
statement = select(self._index._resources["Source"])
results = session.execute(statement).all()
for result in results:
available_ids.append(result[0].id)