From 73e777a48c52829a34674549df9b0dc9579283f4 Mon Sep 17 00:00:00 2001 From: Trenton H <797416+stumpylog@users.noreply.github.com> Date: Tue, 8 Sep 2026 08:30:58 -0700 Subject: [PATCH] Fix: skip nested TagSerializer construction when a tag has no children (#14039) TagSerializer.get_children() built a full nested TagSerializer(many=True) for every tag, even when it had zero children, likely the common case for most tags and maybe even most installs. Constructing a DRF ModelSerializer isn't free (field introspection, deepcopy of declared fields, i18n lookups all re-run per instantiation), so this scaled GET /api/tags/ linearly with tag count in pure Python overhead, unrelated to SQL query count. --- src/documents/serialisers.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/documents/serialisers.py b/src/documents/serialisers.py index f84ee9922..94504fcd0 100644 --- a/src/documents/serialisers.py +++ b/src/documents/serialisers.py @@ -674,6 +674,9 @@ class TagSerializer(MatchingModelSerializer, OwnedObjectSerializer): ordering = ordering or (Lower("name"),) children = children.order_by(*ordering) + if not children: + return [] + serializer = TagSerializer( children, many=True,