Skip to content

Commit ce037bb

Browse files
committed
fix: add more question answers cache to CSV Serializer
1 parent 4e07054 commit ce037bb

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

app/ModelSerializers/Summit/Registration/SummitAttendeeTicketCSVSerializer.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ final class SummitAttendeeTicketCSVSerializer extends SilverStripeSerializer
5353
'FinalAmountAdjusted' => 'total_paid:json_float',
5454
];
5555

56+
// cache per request
57+
private static array $niceValueCache = [];
58+
private static array $questionLabelCache = [];
59+
5660
/**
5761
* @param null $expand
5862
* @param array $fields
@@ -78,12 +82,20 @@ public function serialize($expand = null, array $fields = [], array $relations =
7882
if (isset($params['ticket_questions'])) {
7983
foreach ($params['ticket_questions'] as $question) {
8084
if (!$question instanceof SummitOrderExtraQuestionType) continue;
81-
$question_label = html_entity_decode(strip_tags($question->getLabel()));
85+
86+
$question_label = self::$questionLabelCache[$question->getId()]
87+
??= html_entity_decode(strip_tags($question->getLabel()));
8288
$values[$question_label] = '';
89+
8390
if (!is_null($ticket_owner)) {
8491
$value = $ticket_owner->getExtraQuestionAnswerValueByQuestion($question);
8592
if(is_null($value)) continue;
86-
$values[$question_label] = $question->getNiceValue($value);
93+
94+
$cacheKey = $question->getId() . '|' . $value;
95+
$value = self::$niceValueCache[$cacheKey]
96+
??= $question->getNiceValue($value);
97+
98+
$values[$question_label] = $value;
8799
}
88100
}
89101
}

0 commit comments

Comments
 (0)