Commit 9d903e4d authored by jyong's avatar jyong

add clean unused dataset command

parent dda6061f
...@@ -223,21 +223,28 @@ def clean_unused_dataset_indexes(): ...@@ -223,21 +223,28 @@ def clean_unused_dataset_indexes():
Document.archived == False, Document.archived == False,
Document.updated_at > thirty_days_ago Document.updated_at > thirty_days_ago
).all() ).all()
if not documents and len(documents) > 0: if not documents or len(documents) == 0:
try: try:
update_params = { all_documents = db.session.query(Document).filter(
Document.enabled: False Document.dataset_id == dataset.id,
} Document.indexing_status == 'completed',
Document.enabled == True,
Document.query.filter_by(dataset_id=dataset.id).update(update_params) Document.archived == False,
db.session.commit() ).all()
# remove index if all_documents and len(all_documents)>0:
vector_index = IndexBuilder.get_index(dataset, 'high_quality') update_params = {
kw_index = IndexBuilder.get_index(dataset, 'economy') Document.enabled: False
# delete from vector index }
if vector_index:
vector_index.delete() Document.query.filter_by(dataset_id=dataset.id).update(update_params)
kw_index.delete() db.session.commit()
# remove index
vector_index = IndexBuilder.get_index(dataset, 'high_quality')
kw_index = IndexBuilder.get_index(dataset, 'economy')
# delete from vector index
if vector_index:
vector_index.delete()
kw_index.delete()
except Exception as e: except Exception as e:
click.echo( click.echo(
click.style('clean dataset index error: {} {}'.format(e.__class__.__name__, str(e)), click.style('clean dataset index error: {} {}'.format(e.__class__.__name__, str(e)),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment