Remove bloat from Survey response record to reduce json serialisation time
This commit is contained in:
parent
f49d96152e
commit
da595da89e
2 changed files with 22 additions and 17 deletions
|
|
@ -217,11 +217,18 @@ sub session {
|
|||
|
||||
Serializes the internal perl hash representing the Response to a JSON string
|
||||
|
||||
To reduce json serialization time and db bloat, we only serialize the bare essentials
|
||||
|
||||
=cut
|
||||
|
||||
sub freeze {
|
||||
my $self = shift;
|
||||
return to_json($self->response);
|
||||
|
||||
# These are the only properties of the response hash that we serialize:
|
||||
my @props = qw(responses lastResponse questionsAnswered startTime tags);
|
||||
my %serialize;
|
||||
@serialize{@props} = @{$self->response}{@props};
|
||||
return to_json(\%serialize);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -560,7 +567,10 @@ sub recordResponses {
|
|||
my $aValid = 0;
|
||||
my $qId = $question->{id};
|
||||
|
||||
$newResponse{ $qId }->{comment} = $responses->{ "${qId}comment" };
|
||||
my $comment = $responses->{ "${qId}comment" };
|
||||
if (defined $comment && length $comment) {
|
||||
$newResponse{ $qId }->{comment} = $comment;
|
||||
}
|
||||
|
||||
for my $answer ( @{ $question->{answers} } ) {
|
||||
my $aId = $answer->{id};
|
||||
|
|
@ -577,13 +587,13 @@ sub recordResponses {
|
|||
next;
|
||||
}
|
||||
}
|
||||
elsif ( $questionType eq 'Date' ) {
|
||||
# Must be a valid date (until we get date i18n this is limited to YYYY/MM/DD)
|
||||
if ($recordedAnswer !~ m|^\d{4}/\d{1,2}/\d{1,2}$|) {
|
||||
$self->session->log->debug("Invalid $questionType: $recordedAnswer");
|
||||
next;
|
||||
}
|
||||
}
|
||||
# elsif ( $questionType eq 'Date' ) {
|
||||
# # Accept any date input until we get per-question validation options
|
||||
# if ($recordedAnswer !~ m|^\d{4}/\d{1,2}/\d{1,2}$|) {
|
||||
# $self->session->log->debug("Invalid $questionType: $recordedAnswer");
|
||||
# next;
|
||||
# }
|
||||
# }
|
||||
elsif ( $questionType eq 'Number' || $questionType eq 'Slider' ) {
|
||||
if ( $answer->{max} =~ /\d/ and $recordedAnswer > $answer->{max} ) {
|
||||
$self->session->log->debug("Invalid $questionType: $recordedAnswer");
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ my $session = WebGUI::Test->session;
|
|||
|
||||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
my $tests = 114;
|
||||
my $tests = 113;
|
||||
plan tests => $tests + 1;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
|
@ -564,9 +564,6 @@ cmp_deeply(
|
|||
value => 1, # 'recordedAnswer' value used because question is multi-choice
|
||||
verbatim => 'Section 1, question 0, answer 0 verbatim',
|
||||
},
|
||||
'1-1' => {
|
||||
comment => undef,
|
||||
}
|
||||
},
|
||||
'recordResponses: verbatim answer recorded responses correctly'
|
||||
);
|
||||
|
|
@ -594,9 +591,6 @@ cmp_deeply(
|
|||
'time' => num(time(), 3),
|
||||
value => 'First answer', # submitted answer value used this time because non-mc
|
||||
},
|
||||
'1-1' => {
|
||||
comment => undef,
|
||||
}
|
||||
},
|
||||
'recordResponses: recorded responses correctly, two questions, one answer, comments, values and time'
|
||||
);
|
||||
|
|
@ -783,7 +777,8 @@ cmp_deeply(
|
|||
},
|
||||
'Valid value recorded correctly'
|
||||
);
|
||||
is($rJSON->responses->{'1-1-0'}, undef, 'Invalid date ignored');
|
||||
# All date input accepted until validation options supported
|
||||
#is($rJSON->responses->{'1-1-0'}, undef, 'Invalid date ignored');
|
||||
|
||||
########
|
||||
# Number
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue