Skip to content

Commit

Permalink
Update stats with query modules (#304)
Browse files Browse the repository at this point in the history
  • Loading branch information
antonio2368 committed Nov 26, 2021
1 parent 18f9d19 commit d277dd4
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/query/metadata.hpp
Expand Up @@ -87,4 +87,4 @@ struct ExecutionStats {

std::string ExecutionStatsKeyToString(ExecutionStats::Key key);

} // namespace query
} // namespace query
81 changes: 66 additions & 15 deletions src/query/procedure/mg_procedure_impl.cpp
Expand Up @@ -1583,7 +1583,11 @@ mgp_error mgp_vertex_set_property(struct mgp_vertex *v, const char *property_nam
}
}

auto *trigger_ctx_collector = v->graph->ctx->trigger_context_collector;
auto &ctx = v->graph->ctx;

ctx->execution_stats[query::ExecutionStats::Key::UPDATED_PROPERTIES] += 1;

auto *trigger_ctx_collector = ctx->trigger_context_collector;
if (!trigger_ctx_collector || !trigger_ctx_collector->ShouldRegisterObjectPropertyChange<query::VertexAccessor>()) {
return;
}
Expand Down Expand Up @@ -1619,8 +1623,12 @@ mgp_error mgp_vertex_add_label(struct mgp_vertex *v, mgp_label label) {
}
}

if (v->graph->ctx->trigger_context_collector) {
v->graph->ctx->trigger_context_collector->RegisterSetVertexLabel(v->impl, label_id);
auto &ctx = v->graph->ctx;

ctx->execution_stats[query::ExecutionStats::Key::CREATED_LABELS] += 1;

if (ctx->trigger_context_collector) {
ctx->trigger_context_collector->RegisterSetVertexLabel(v->impl, label_id);
}
});
}
Expand All @@ -1646,8 +1654,13 @@ mgp_error mgp_vertex_remove_label(struct mgp_vertex *v, mgp_label label) {
throw SerializationException{"Cannot serialize removing a label from a vertex."};
}
}
if (v->graph->ctx->trigger_context_collector) {
v->graph->ctx->trigger_context_collector->RegisterRemovedVertexLabel(v->impl, label_id);

auto &ctx = v->graph->ctx;

ctx->execution_stats[query::ExecutionStats::Key::DELETED_LABELS] += 1;

if (ctx->trigger_context_collector) {
ctx->trigger_context_collector->RegisterRemovedVertexLabel(v->impl, label_id);
}
});
}
Expand Down Expand Up @@ -1994,6 +2007,10 @@ mgp_error mgp_edge_set_property(struct mgp_edge *e, const char *property_name, m
}
}

auto &ctx = e->from.graph->ctx;

ctx->execution_stats[query::ExecutionStats::Key::UPDATED_PROPERTIES] += 1;

auto *trigger_ctx_collector = e->from.graph->ctx->trigger_context_collector;
if (!trigger_ctx_collector || !trigger_ctx_collector->ShouldRegisterObjectPropertyChange<query::EdgeAccessor>()) {
return;
Expand Down Expand Up @@ -2059,8 +2076,12 @@ mgp_error mgp_graph_create_vertex(struct mgp_graph *graph, mgp_memory *memory, m
throw ImmutableObjectException{"Cannot create a vertex in an immutable graph!"};
}
auto vertex = graph->impl->InsertVertex();
if (graph->ctx->trigger_context_collector) {
graph->ctx->trigger_context_collector->RegisterCreatedObject(vertex);

auto &ctx = graph->ctx;
ctx->execution_stats[query::ExecutionStats::Key::CREATED_NODES] += 1;

if (ctx->trigger_context_collector) {
ctx->trigger_context_collector->RegisterCreatedObject(vertex);
}
return NewRawMgpObject<mgp_vertex>(memory, vertex, graph);
},
Expand All @@ -2087,8 +2108,17 @@ mgp_error mgp_graph_delete_vertex(struct mgp_graph *graph, mgp_vertex *vertex) {
throw SerializationException{"Cannot serialize removing a vertex."};
}
}
if (graph->ctx->trigger_context_collector && *result) {
graph->ctx->trigger_context_collector->RegisterDeletedObject(**result);

if (!*result) {
return;
}

auto &ctx = graph->ctx;

ctx->execution_stats[query::ExecutionStats::Key::DELETED_NODES] += 1;

if (ctx->trigger_context_collector) {
ctx->trigger_context_collector->RegisterDeletedObject(**result);
}
});
}
Expand All @@ -2113,10 +2143,20 @@ mgp_error mgp_graph_detach_delete_vertex(struct mgp_graph *graph, mgp_vertex *ve
}
}

auto *trigger_ctx_collector = graph->ctx->trigger_context_collector;
if (!trigger_ctx_collector || !*result) {
if (!*result) {
return;
}

auto &ctx = graph->ctx;

ctx->execution_stats[query::ExecutionStats::Key::DELETED_NODES] += 1;
ctx->execution_stats[query::ExecutionStats::Key::DELETED_EDGES] += static_cast<int64_t>((*result)->second.size());

auto *trigger_ctx_collector = ctx->trigger_context_collector;
if (!trigger_ctx_collector) {
return;
}

trigger_ctx_collector->RegisterDeletedObject((*result)->first);
if (!trigger_ctx_collector->ShouldRegisterDeletedObject<query::EdgeAccessor>()) {
return;
Expand Down Expand Up @@ -2149,8 +2189,12 @@ mgp_error mgp_graph_create_edge(mgp_graph *graph, mgp_vertex *from, mgp_vertex *
throw SerializationException{"Cannot serialize creating an edge."};
}
}
if (graph->ctx->trigger_context_collector) {
graph->ctx->trigger_context_collector->RegisterCreatedObject(*edge);
auto &ctx = graph->ctx;

ctx->execution_stats[query::ExecutionStats::Key::CREATED_EDGES] += 1;

if (ctx->trigger_context_collector) {
ctx->trigger_context_collector->RegisterCreatedObject(*edge);
}
return NewRawMgpObject<mgp_edge>(memory, edge.GetValue(), from->graph);
},
Expand All @@ -2176,8 +2220,15 @@ mgp_error mgp_graph_delete_edge(struct mgp_graph *graph, mgp_edge *edge) {
throw SerializationException{"Cannot serialize removing an edge."};
}
}
if (graph->ctx->trigger_context_collector && *result) {
graph->ctx->trigger_context_collector->RegisterDeletedObject(**result);

if (!*result) {
return;
}
auto &ctx = graph->ctx;

ctx->execution_stats[query::ExecutionStats::Key::DELETED_EDGES] += 1;
if (ctx->trigger_context_collector) {
ctx->trigger_context_collector->RegisterDeletedObject(**result);
}
});
}
Expand Down

0 comments on commit d277dd4

Please sign in to comment.