improve-delete
This commit is contained in:
parent
4c2527f416
commit
41666cf38e
1 changed files with 30 additions and 37 deletions
|
|
@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
from typing import TYPE_CHECKING, Any
|
from typing import TYPE_CHECKING, Any
|
||||||
|
|
||||||
|
|
@ -191,46 +192,38 @@ class FalkorDriver(GraphDriver):
|
||||||
await self.client.connection.close()
|
await self.client.connection.close()
|
||||||
|
|
||||||
async def delete_all_indexes(self) -> None:
|
async def delete_all_indexes(self) -> None:
|
||||||
from collections import defaultdict
|
result = await self.execute_query("CALL db.indexes()")
|
||||||
|
if not result:
|
||||||
result = await self.execute_query('CALL db.indexes()')
|
|
||||||
if result is None:
|
|
||||||
return
|
return
|
||||||
|
|
||||||
records, _, _ = result
|
|
||||||
|
|
||||||
# Organize indexes by type and label
|
|
||||||
range_indexes = defaultdict(list)
|
|
||||||
fulltext_indexes = defaultdict(list)
|
|
||||||
entity_types = {}
|
|
||||||
|
|
||||||
for record in records:
|
|
||||||
label = record['label']
|
|
||||||
entity_types[label] = record['entitytype']
|
|
||||||
|
|
||||||
for field_name, index_type in record['types'].items():
|
|
||||||
if 'RANGE' in index_type:
|
|
||||||
range_indexes[label].append(field_name)
|
|
||||||
if 'FULLTEXT' in index_type:
|
|
||||||
fulltext_indexes[label].append(field_name)
|
|
||||||
|
|
||||||
# Drop all range indexes
|
|
||||||
for label, fields in range_indexes.items():
|
|
||||||
for field in fields:
|
|
||||||
await self.execute_query(f'DROP INDEX ON :{label}({field})')
|
|
||||||
|
|
||||||
# Drop all fulltext indexes
|
records, _, _ = result
|
||||||
for label, fields in fulltext_indexes.items():
|
drop_tasks = []
|
||||||
entity_type = entity_types[label]
|
|
||||||
for field in fields:
|
for record in records:
|
||||||
if entity_type == 'NODE':
|
label = record["label"]
|
||||||
await self.execute_query(
|
entity_type = record["entitytype"]
|
||||||
f'DROP FULLTEXT INDEX FOR (n:{label}) ON (n.{field})'
|
|
||||||
)
|
for field_name, index_type in record["types"].items():
|
||||||
elif entity_type == 'RELATIONSHIP':
|
if "RANGE" in index_type:
|
||||||
await self.execute_query(
|
drop_tasks.append(
|
||||||
f'DROP FULLTEXT INDEX FOR ()-[e:{label}]-() ON (e.{field})'
|
self.execute_query(f"DROP INDEX ON :{label}({field_name})")
|
||||||
)
|
)
|
||||||
|
elif "FULLTEXT" in index_type:
|
||||||
|
if entity_type == "NODE":
|
||||||
|
drop_tasks.append(
|
||||||
|
self.execute_query(
|
||||||
|
f"DROP FULLTEXT INDEX FOR (n:{label}) ON (n.{field_name})"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
elif entity_type == "RELATIONSHIP":
|
||||||
|
drop_tasks.append(
|
||||||
|
self.execute_query(
|
||||||
|
f"DROP FULLTEXT INDEX FOR ()-[e:{label}]-() ON (e.{field_name})"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
if drop_tasks:
|
||||||
|
await asyncio.gather(*drop_tasks)
|
||||||
|
|
||||||
def clone(self, database: str) -> 'GraphDriver':
|
def clone(self, database: str) -> 'GraphDriver':
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue