From 8cf3e863fbb33ed61988702e6e8321fe8340523b Mon Sep 17 00:00:00 2001 From: Alexandr Burdiyan Date: Tue, 17 Dec 2024 17:30:55 +0100 Subject: [PATCH] fix(backend): fix memory issues with huge page sizes --- backend/api/documents/v3alpha/documents.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/api/documents/v3alpha/documents.go b/backend/api/documents/v3alpha/documents.go index 82c0acde..47fb15d8 100644 --- a/backend/api/documents/v3alpha/documents.go +++ b/backend/api/documents/v3alpha/documents.go @@ -226,7 +226,7 @@ func (srv *Server) ListRootDocuments(ctx context.Context, in *documents.ListRoot } out := &documents.ListRootDocumentsResponse{ - Documents: make([]*documents.DocumentListItem, 0, in.PageSize), + Documents: make([]*documents.DocumentListItem, 0, min(in.PageSize, 300)), // Avoid allocating huge slice if huge page size was requested. Number is arbitrary. } namespaceGlob := "hm://*" @@ -314,7 +314,7 @@ func (srv *Server) ListDocuments(ctx context.Context, in *documents.ListDocument } out := &documents.ListDocumentsResponse{ - Documents: make([]*documents.DocumentListItem, 0, in.PageSize), + Documents: make([]*documents.DocumentListItem, 0, min(in.PageSize, 300)), // Avoid allocating huge slice if huge page size was requested. Number is arbitrary. } namespaceGlob := "hm://" + ns.String() + "*"