Changes between Version 1 and Version 2 of Ticket #32449, comment 3


Ignore:
Timestamp:
Feb 16, 2021, 2:45:31 PM (3 years ago)
Author:
João Carneiro Haas

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #32449, comment 3

    v1 v2  
    88{{{
    99#!python
    10 # nodes/models.py
     10# graph/models.py
    1111
    1212class Node(models.Model):
     
    2424
    2525# b_qs is a really complex 'B' queryset
    26 b_qs = b_qs.objects.select_related('A').annotate(graph_child_count=RawSQL("""
    27     WITH RECURSIVE graph_children(id) AS (
     26b_qs = b_qs.objects.select_related('a').annotate(graph_child_count=RawSQL("""
     27    WITH RECURSIVE children(id) AS (
    2828        SELECT "e"."child_id"
    29           FROM "nodes_edge" AS "e"
    30          WHERE "e"."parent_id" = "nodes_a"."node_id"
     29          FROM "graph_edge" AS "e"
     30         WHERE "e"."parent_id" = "graph_a"."node_id"
    3131         UNION
    3232        SELECT "e"."child_id"
    33           FROM "nodes_edge" AS "e", "graph_children"
    34          WHERE "e"."parent_id" = "graph_children"."id"
     33          FROM "graph_edge" AS "e", "children"
     34         WHERE "e"."parent_id" = "children"."id"
    3535    ) SELECT COUNT(*) FROM "graph_children"
    3636""", [])).filter(graph_child_count__lt=10).count()
Back to Top