Przeglądaj źródła

commit 优化世系查询展示

Hai Lin 6 dni temu
rodzic
commit
675e248942
1 zmienionych plików z 27 dodań i 10 usunięć
  1. 27 10
      app.py

+ 27 - 10
app.py

@@ -1282,17 +1282,30 @@ def get_lineage(member_id):
                 ancestor_ids.append(parent['id'])
                 displayed_ids.add(parent['id'])
                 
-                # Get siblings of this ancestor
+                # Get siblings of this ancestor (father's brothers)
+                # First get grandparent (parent's father)
                 cursor.execute("""
-                    SELECT c.id, c.name, c.simplified_name, c.name_word, c.name_word_generation,
-                           EXISTS(SELECT 1 FROM family_relation_info WHERE parent_mid = c.id AND relation_type IN (1, 2)) as has_children
+                    SELECT gp.id
                     FROM family_relation_info r
-                    JOIN family_member_info c ON r.child_mid = c.id
-                    WHERE r.parent_mid = %s AND r.relation_type IN (1, 2) AND c.id != %s
-                    ORDER BY c.id
-                    LIMIT 30
-                """, (parent['id'], current_id))
-                parent_siblings = cursor.fetchall()
+                    JOIN family_member_info gp ON r.parent_mid = gp.id
+                    WHERE r.child_mid = %s AND r.relation_type IN (1, 2)
+                    LIMIT 1
+                """, (parent['id'],))
+                grandparent = cursor.fetchone()
+                
+                parent_siblings = []
+                if grandparent:
+                    # Get siblings of parent (father's brothers)
+                    cursor.execute("""
+                        SELECT c.id, c.name, c.simplified_name, c.name_word, c.name_word_generation,
+                               EXISTS(SELECT 1 FROM family_relation_info WHERE parent_mid = c.id AND relation_type IN (1, 2)) as has_children
+                        FROM family_relation_info r
+                        JOIN family_member_info c ON r.child_mid = c.id
+                        WHERE r.parent_mid = %s AND r.relation_type IN (1, 2) AND c.id != %s
+                        ORDER BY c.id
+                        LIMIT 30
+                    """, (grandparent['id'], parent['id']))
+                    parent_siblings = cursor.fetchall()
                 
                 # Mark sibling IDs as displayed
                 for sibling in parent_siblings:
@@ -1308,7 +1321,11 @@ def get_lineage(member_id):
                 """, (parent['id'],))
                 total_children = cursor.fetchone()['count']
                 
-                show_expand = total_children > len(parent_siblings) + 1  # +1 for the current child
+                # Check if current child is displayed (current_id is the child of parent)
+                child_displayed = current_id in displayed_ids
+                
+                # Show expand if there are children not displayed
+                show_expand = total_children > (1 if child_displayed else 0)
                 
                 parent['show_expand'] = show_expand