diff options
author | Matthew Somerville <matthew@mysociety.org> | 2015-02-10 17:10:40 +0000 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2015-02-13 10:09:33 +0000 |
commit | 3571f96251df08dd8a9dda3ec4e1fadf30d6c63d (patch) | |
tree | 6cd0d05d06a51dfdcbe183c4c10b38c0a15c6231 /perllib/FixMyStreet/DB | |
parent | 9591ba909210b2a628237074b54e5eb3c6536856 (diff) |
Create timezone objects only once at startup.
Cache a DateTime::TimeZone::Local object, so that in an environment
where /etc/localtime is a copy of a timezone file, we don't repeatedly
walk all the timezone files to find the matching one.
Diffstat (limited to 'perllib/FixMyStreet/DB')
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Alert.pm | 10 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Comment.pm | 10 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 12 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Questionnaire.pm | 10 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/AlertType.pm | 16 |
5 files changed, 8 insertions, 50 deletions
diff --git a/perllib/FixMyStreet/DB/Result/Alert.pm b/perllib/FixMyStreet/DB/Result/Alert.pm index 4ce72f873..c64cb2ff4 100644 --- a/perllib/FixMyStreet/DB/Result/Alert.pm +++ b/perllib/FixMyStreet/DB/Result/Alert.pm @@ -69,24 +69,16 @@ __PACKAGE__->belongs_to( # You can replace this text with custom code or comments, and it will be preserved on regeneration -use DateTime::TimeZone; use Moose; use namespace::clean -except => [ 'meta' ]; with 'FixMyStreet::Roles::Abuser'; -my $tz = DateTime::TimeZone->new( name => "local" ); - -my $tz_f; -$tz_f = DateTime::TimeZone->new( name => FixMyStreet->config('TIME_ZONE') ) - if FixMyStreet->config('TIME_ZONE'); - my $stz = sub { my ( $orig, $self ) = ( shift, shift ); my $s = $self->$orig(@_); return $s unless $s && UNIVERSAL::isa($s, "DateTime"); - $s->set_time_zone($tz); - $s->set_time_zone($tz_f) if $tz_f; + FixMyStreet->set_time_zone($s); return $s; }; diff --git a/perllib/FixMyStreet/DB/Result/Comment.pm b/perllib/FixMyStreet/DB/Result/Comment.pm index 3fae6860a..836462ed5 100644 --- a/perllib/FixMyStreet/DB/Result/Comment.pm +++ b/perllib/FixMyStreet/DB/Result/Comment.pm @@ -95,25 +95,17 @@ __PACKAGE__->belongs_to( __PACKAGE__->load_components("+FixMyStreet::DB::RABXColumn"); __PACKAGE__->rabx_column('extra'); -use DateTime::TimeZone; use Image::Size; use Moose; use namespace::clean -except => [ 'meta' ]; with 'FixMyStreet::Roles::Abuser'; -my $tz = DateTime::TimeZone->new( name => "local" ); - -my $tz_f; -$tz_f = DateTime::TimeZone->new( name => FixMyStreet->config('TIME_ZONE') ) - if FixMyStreet->config('TIME_ZONE'); - my $stz = sub { my ( $orig, $self ) = ( shift, shift ); my $s = $self->$orig(@_); return $s unless $s && UNIVERSAL::isa($s, "DateTime"); - $s->set_time_zone($tz); - $s->set_time_zone($tz_f) if $tz_f; + FixMyStreet->set_time_zone($s); return $s; }; diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index 34d740912..3c620ba84 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -153,7 +153,6 @@ __PACKAGE__->load_components("+FixMyStreet::DB::RABXColumn"); __PACKAGE__->rabx_column('extra'); __PACKAGE__->rabx_column('geocode'); -use DateTime::TimeZone; use Image::Size; use Moose; use namespace::clean -except => [ 'meta' ]; @@ -316,18 +315,11 @@ sub council_states { return wantarray ? keys %{$states} : $states; } -my $tz = DateTime::TimeZone->new( name => "local" ); - -my $tz_f; -$tz_f = DateTime::TimeZone->new( name => FixMyStreet->config('TIME_ZONE') ) - if FixMyStreet->config('TIME_ZONE'); - my $stz = sub { my ( $orig, $self ) = ( shift, shift ); my $s = $self->$orig(@_); return $s unless $s && UNIVERSAL::isa($s, "DateTime"); - $s->set_time_zone($tz); - $s->set_time_zone($tz_f) if $tz_f; + FixMyStreet->set_time_zone($s); return $s; }; @@ -745,7 +737,7 @@ sub update_from_open311_service_request { # of course if local timezone is not the one that went into the data # base then we're also in trouble my $lastupdate = $self->lastupdate; - $lastupdate->set_time_zone( DateTime::TimeZone->new( name => 'local' ) ); + $lastupdate->set_time_zone( FixMyStreet->local_time_zone ); # update from open311 is older so skip if ( $req_time < $lastupdate ) { diff --git a/perllib/FixMyStreet/DB/Result/Questionnaire.pm b/perllib/FixMyStreet/DB/Result/Questionnaire.pm index 7f9c79d9a..6f2941546 100644 --- a/perllib/FixMyStreet/DB/Result/Questionnaire.pm +++ b/perllib/FixMyStreet/DB/Result/Questionnaire.pm @@ -43,22 +43,14 @@ __PACKAGE__->belongs_to( # Created by DBIx::Class::Schema::Loader v0.07035 @ 2013-09-10 17:11:54 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:oL1Hk4/bNG14CY74GA75SA -use DateTime::TimeZone; use Moose; use namespace::clean -except => [ 'meta' ]; -my $tz = DateTime::TimeZone->new( name => "local" ); - -my $tz_f; -$tz_f = DateTime::TimeZone->new( name => FixMyStreet->config('TIME_ZONE') ) - if FixMyStreet->config('TIME_ZONE'); - my $stz = sub { my ( $orig, $self ) = ( shift, shift ); my $s = $self->$orig(@_); return $s unless $s && UNIVERSAL::isa($s, "DateTime"); - $s->set_time_zone($tz); - $s->set_time_zone($tz_f) if $tz_f; + FixMyStreet->set_time_zone($s); return $s; }; diff --git a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm index b704fa7dd..ad180cbd5 100644 --- a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm +++ b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm @@ -115,24 +115,14 @@ sub email_alerts ($) { } $data{data} .= $row->{item_name} . ' : ' if $row->{item_name} && !$row->{item_anonymous}; if ( $cobrand->include_time_in_update_alerts ) { - # this is basically recreating the code from the inflate wrapper - # in the database model. - my $tz; - if ( FixMyStreet->config('TIME_ZONE') ) { - $tz = FixMyStreet->config('TIME_ZONE'); - } - my $parser = DateTime::Format::Pg->new(); my $dt = $parser->parse_timestamp( $row->{item_confirmed} ); - my $l_tz = DateTime::TimeZone->new( name => "local" ); # We need to always set this otherwise we end up with the DateTime # object being in the floating timezone in which case applying a # subsequent timezone set will have no effect. - $dt->set_time_zone( $l_tz ); - if ( $tz ) { - my $tz_obj = DateTime::TimeZone->new( name => $tz ); - $dt->set_time_zone( $tz_obj ); - } + # this is basically recreating the code from the inflate wrapper + # in the database model. + FixMyStreet->set_time_zone($dt); $data{data} .= $cobrand->prettify_dt( $dt, 'alert' ) . "\n\n"; } $data{data} .= $row->{item_text} . "\n\n------\n\n"; |