Skip to content

Commit 1076b18

Browse files
authored
[core][feat] Improve update index efficiency (#2083)
1 parent 6255c40 commit 1076b18

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

fixcore/fixcore/db/db_access.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454

5555
log = logging.getLogger(__name__)
5656

57+
MigrateAlways = False
5758
CurrentDatabaseVersion = 2
5859

5960

@@ -116,7 +117,8 @@ async def __migrate(self) -> None:
116117
system_data = SystemData(uuid_str(), utc(), CurrentDatabaseVersion)
117118
git_hash = current_git_hash()
118119
if (
119-
system_data.db_version != CurrentDatabaseVersion
120+
MigrateAlways
121+
or system_data.db_version != CurrentDatabaseVersion
120122
or system_data.version is None
121123
or git_hash is None
122124
or git_hash != system_data.version

fixcore/fixcore/db/graphdb.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,16 +1299,18 @@ def create_node_indexes(nodes: VertexCollection) -> None:
12991299
# old update node index: remove if still exists
13001300
if "update_nodes_ref_id" in node_idxes:
13011301
nodes.delete_index("update_nodes_ref_id")
1302+
if "update_nodes" in node_idxes:
1303+
log.info(f"Remove index update_nodes on {nodes.name}")
1304+
nodes.delete_index("update_nodes")
13021305

13031306
# this index will hold all the necessary data to query for an update (index only query)
1304-
if "update_nodes" not in node_idxes:
1305-
log.info(f"Add index update_nodes on {nodes.name}")
1307+
if "update_replace_nodes" not in node_idxes:
1308+
log.info(f"Add index update_replace_nodes on {nodes.name}")
13061309
nodes.add_persistent_index(
1307-
# if _key was defined as first property, the optimizer would use it in case
1308-
# a simple id() query would be executed.
1309-
["refs.cloud_id", "refs.account_id", "refs.region_id", "hash", "hist_hash", "created", "_key"],
1310+
["refs.account_id", "refs.cloud_id"],
1311+
storedValues=["_key", "hash", "hist_hash", "created"],
13101312
sparse=False,
1311-
name="update_nodes",
1313+
name="update_replace_nodes",
13121314
)
13131315

13141316
if "kinds_id_name_ctime" not in node_idxes:
@@ -1352,13 +1354,19 @@ def create_update_collection_indexes(progress: StandardCollection, node_history:
13521354

13531355
def create_update_edge_indexes(edges: EdgeCollection) -> None:
13541356
edge_idxes = {idx["name"]: idx for idx in cast(List[Json], edges.indexes())}
1357+
# delete old index
1358+
if "update_edges_ref_id" in edge_idxes:
1359+
log.info(f"Remove index update_edges_ref_id on {edges.name}")
1360+
edges.delete_index("update_edges_ref_id")
1361+
13551362
# this index will hold all the necessary data to query for an update (index only query)
1356-
if "update_edges_ref_id" not in edge_idxes:
1357-
log.info(f"Add index update_edges_ref_id on {edges.name}")
1363+
if "update_edges_replace_nodes" not in edge_idxes:
1364+
log.info(f"Add index update_edges_replace_nodes on {edges.name}")
13581365
edges.add_persistent_index(
1359-
["_key", "_from", "_to", "refs.cloud_id", "refs.account_id", "refs.region_id"],
1366+
["refs.account_id", "refs.cloud_id"],
1367+
storedValues=["_key", "_from", "_to"],
13601368
sparse=False,
1361-
name="update_edges_ref_id",
1369+
name="update_edges_replace_nodes",
13621370
)
13631371
outer_edge_ts_index_name = "outer_edge_timestamp_index"
13641372
if outer_edge_ts_index_name not in edge_idxes:

0 commit comments

Comments
 (0)