fix(caldav): render a resource's content once per request

A multistatus response asks for a resource's iCal content once per
requested property. It is now rendered once per resource and request.
This commit is contained in:
kolaente
2026-11-05 15:42:45 +01:00
parent daa4676e94
commit fbedeae73e
2 changed files with 50 additions and 0 deletions
+11
View File
@@ -1110,6 +1110,9 @@ type VikunjaProjectResourceAdapter struct {
isPrincipal bool
isCollection bool
// Rendered once per request: a multistatus response asks for it per requested property.
content *string
}
// IsCollection checks if the resoure in the adapter is a collection
@@ -1153,6 +1156,14 @@ func (vlra *VikunjaProjectResourceAdapter) CalculateEtag() string {
// GetContent returns the content string of a resource (a task in our case)
func (vlra *VikunjaProjectResourceAdapter) GetContent() string {
if vlra.content == nil {
content := vlra.renderContent()
vlra.content = &content
}
return *vlra.content
}
func (vlra *VikunjaProjectResourceAdapter) renderContent() string {
if vlra.project != nil && vlra.projectTasks != nil {
return caldav.GetCaldavTodosForTasks(vlra.project, vlra.projectTasks)
}
+39
View File
@@ -0,0 +1,39 @@
// Vikunja is a to-do list application to facilitate your life.
// Copyright 2018-present Vikunja and contributors. All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package caldav
import (
"testing"
"code.vikunja.io/api/pkg/models"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestResourceContentIsRenderedOnce(t *testing.T) {
task := &models.Task{UID: "uid-rendered-once", Title: "first"}
rr := &VikunjaProjectResourceAdapter{task: task}
content := rr.GetContent()
require.Contains(t, content, "SUMMARY:first")
// A second render would pick up the new title.
task.Title = "second"
assert.Equal(t, content, rr.GetContent())
assert.Equal(t, int64(len(content)), rr.GetContentSize())
}