25 restructure network page - #27
Conversation
…es also for contexts
…backend_django into 25-restructure-network-page
…ntext deleted, duckDB memory fix (hopefully)
There was a problem hiding this comment.
🟡 Changes recommended
The new significant-network truncation logic can return links that reference nodes omitted from points, and the edge ranking key doesn’t correctly treat NaN as “missing,” risking incorrect top-edge selection.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR updates the network-related backend APIs to better support the restructured Network Page UI, including context-aware caching, richer node metadata in responses, backend-side ranking/truncation of significant edges, and improved signaling of external enrichment API failures.
Changes:
- Fix line-plot aggregation behavior when
PRESERVE_PRIVACYis disabled by filtering the underlying DataFrame (not the GroupBy) before aggregation. - Add
data_typeto node/typeahead payloads and compute/return node/edge ranking metadata on the backend (including truncation to bounded result sets). - Add/adjust caching for context-scoped variable and context-node-id queries; surface g:Profiler/Reactome outage signals in community-annotation status responses.
File summaries
| File | Description |
|---|---|
| network/views/plotting.py | Adjusts line-plot aggregation to avoid GroupBy misuse when privacy filtering is off. |
| network/views/network.py | Extends typeahead response payload with data_type. |
| network/views/metagraph.py | Adds backend ranking/truncation + node degree stats in Cosmograph/Metagraph responses; removes Cosmograph caching. |
| network/views/general.py | Adds context-scoped caching for variables and refines availableLayers computation. |
| network/views/community_annotation.py | Unwraps task result and exposes reactomeFailed / gprofilerFailed flags. |
| network/tasks.py | Includes data_type/xrefs in moDiNA point shaping; propagates enrichment API failure states. |
| network/queries.py | Adds data_type to node/typeahead queries; caches get_context_node_ids(). |
| network/enrichment.py | Distinguishes “API failure” (None) from “no significant results” (empty) for external enrichment calls. |
| network/contexts/contexts.py | Clears context-related cache keys on context deletion to avoid ID reuse serving stale data. |
Review details
- Files reviewed: 9/9 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| candidate_links.sort(key=_edge_ranking_sort_key) | ||
| top_edges = candidate_links[:max_edges] | ||
| for rank, edge in enumerate(top_edges, start=1): | ||
| edge['rank'] = rank | ||
|
|
||
| ranked_node_ids = sorted( | ||
| weighted_degree.keys(), | ||
| key=lambda node_id: (-weighted_degree[node_id], -degree[node_id], node_id), | ||
| ) | ||
| node_stats_by_id = { | ||
| node_id: {'degree': degree[node_id], 'weighted_degree': weighted_degree[node_id], 'rank': rank} | ||
| for rank, node_id in enumerate(ranked_node_ids[:max_nodes], start=1) | ||
| } |
There was a problem hiding this comment.
No problem when truncated it's not used for the network. The current Networks ranking is calculated frontend side
shouldn't be None but fix just in case Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…backend_django into 25-restructure-network-page
There was a problem hiding this comment.
🔵 Needs a closer look
The full_network_stats response can return links whose endpoint nodes are missing from points, which can break graph consumers expecting all edge endpoints to be present.
Review details
Suppressed comments (3)
Previously missed (2) — in code that hasn't changed since the last review.
network/queries.py:142
- The cache check uses
cache_key in cacheand thencache.get(cache_key), which causes two Redis round-trips on every cache hit (and this function is called on every keystroke in context-scoped typeahead). You can avoid the extra call by using a singlecache.getwith a None/sentinel check.
network/views/general.py:82 - This condition checks
cache_key not in cachebeforesettings.NO_CACHE, so when NO_CACHE is enabled it still performs a Redis membership check even though caching is effectively disabled. Reordering the condition avoids the unnecessary cache call.
network/views/metagraph.py:556
- When
full_network_statsis enabled,cohort_nodesis restricted tonode_stats_by_id.keys()(top nodes by weighted-degree), butresponse_linksis the (top) edge list ranked by p-value/effect size. These two truncations are independent, so the response can contain links whosesource/targetnodes are missing frompoints, which can break graph consumers expecting every endpoint to exist as a point. Consider including at least all endpoint node_ids fromresponse_linksinpoints(and filling degree/weighted_degree/rank appropriately), or alternatively filteringresponse_linksdown to edges whose endpoints are in the returned node set.
if node_stats_by_id:
cohort_nodes = node_model.objects.filter(node_id__in=node_stats_by_id.keys()).values(
'node_id', 'display_name', 'node_group', 'node_subgroup', 'data_type', 'description', 'xrefs')
else:
- Files reviewed: 9/9 changed files
- Comments generated: 0 new
- Review effort level: Lite
Backend-Side to Frontend Changes to Restructure Network Page: