diff options
-rw-r--r-- | CHANGELOG.md | 3 | ||||
-rw-r--r-- | conf/general.yml-docker | 6 | ||||
-rw-r--r-- | conf/general.yml-example | 4 | ||||
-rw-r--r-- | docs/customising/config.md | 9 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Reports.pm | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/BathNES.pm | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Problem.pm | 12 | ||||
-rw-r--r-- | templates/web/base/admin/extra-metadata-form.html | 2 | ||||
-rw-r--r-- | templates/web/base/common_header_tags.html | 2 | ||||
-rw-r--r-- | templates/web/base/common_scripts.html | 2 | ||||
-rw-r--r-- | templates/web/fixmystreet-uk-councils/footer_extra_js.html | 11 | ||||
-rw-r--r-- | templates/web/oxfordshire/footer_extra_js.html | 8 | ||||
-rw-r--r-- | web/cobrands/fixmystreet/admin.js | 2 |
13 files changed, 52 insertions, 15 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d295fd1f..4b58e5cca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,10 @@ - Remove any use of `my $x if $foo`. #2377 - Fix saving of inspect form data offline. - Add CSRF and time to contact form. + - Make sure admin metadata dropdown index numbers are updated too. - Fix issue with Open311 codes starting with ‘_’. + - Development improvements: + - Make front page cache time configurable. * v2.5 (21st December 2018) - Front end improvements: diff --git a/conf/general.yml-docker b/conf/general.yml-docker index 5a447dbee..fb789daf5 100644 --- a/conf/general.yml-docker +++ b/conf/general.yml-docker @@ -95,7 +95,7 @@ PHOTO_STORAGE_OPTIONS: # it doesn't already exist. Requires the appropriate AWS # permissions. # REGION: 'eu-west-1' # optional, only used if CREATE_BUCKET is set. Controls -# which AWS region the S3 bucket will be created in. + # which AWS region the S3 bucket will be created in. # Location of MapIt, to map points to administrative areas, and what types of # area from it you want to use. If left blank, a default area will be used @@ -225,6 +225,10 @@ GAZE_URL: 'https://gaze.mysociety.org/gaze' # This can be safely left out and will default to '127.0.0.1' even if not present. MEMCACHED_HOST: 'memcached.svc' +# Cache timeout - integer, optional, default 3600s (1 hour) +# Used for cache of front page stats/recent list, and /reports max-age. +CACHE_TIMEOUT: 3600 + # Should problem reports link to the council summary pages? AREA_LINKS_FROM_PROBLEMS: '0' diff --git a/conf/general.yml-example b/conf/general.yml-example index 11902c0b3..8dd4d0a2f 100644 --- a/conf/general.yml-example +++ b/conf/general.yml-example @@ -221,6 +221,10 @@ GAZE_URL: 'https://gaze.mysociety.org/gaze' # This can be safely left out and will default to '127.0.0.1' even if not present. MEMCACHED_HOST: '127.0.0.1' +# Cache timeout - integer, optional, default 3600s (1 hour) +# Used for cache of front page stats/recent list, and /reports max-age. +CACHE_TIMEOUT: 3600 + # Should problem reports link to the council summary pages? AREA_LINKS_FROM_PROBLEMS: '0' diff --git a/docs/customising/config.md b/docs/customising/config.md index f9b2fc213..d83e00472 100644 --- a/docs/customising/config.md +++ b/docs/customising/config.md @@ -50,6 +50,7 @@ The following are all the configuration settings that you can change in `conf/ge * <code><a href="#open311_limit">OPEN311_LIMIT</a></code> * <code><a href="#all_reports_per_page">ALL_REPORTS_PER_PAGE</a></code> * <code><a href="#area_links_from_problems">AREA_LINKS_FROM_PROBLEMS</a></code> +* <code><a href="#cache_timeout">CACHE_TIMEOUT</a></code> ### URLs and directories @@ -1091,6 +1092,14 @@ ALLOWED_COBRANDS: </dd> <dt> + <a name="cache_timeout"><code>CACHE_TIMEOUT</code></a> + </dt> + <dd> + The time, in seconds, that the front page stats/recent list should be cached for. + Also used for the max-age of <code>/reports</code>. Defaults to 3600s (1 hour). + </dd> + + <dt> <a name="gaze_url"><code>GAZE_URL</code></a> </dt> <dd> diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm index 42f5ea288..975b2fdd5 100644 --- a/perllib/FixMyStreet/App/Controller/Reports.pm +++ b/perllib/FixMyStreet/App/Controller/Reports.pm @@ -74,7 +74,8 @@ sub index : Path : Args(0) { } # Down here so that error pages aren't cached. - $c->response->header('Cache-Control' => 'max-age=3600'); + my $max_age = FixMyStreet->config('CACHE_TIMEOUT') // 3600; + $c->response->header('Cache-Control' => 'max-age=' . $max_age); } =head2 display_body_stats diff --git a/perllib/FixMyStreet/Cobrand/BathNES.pm b/perllib/FixMyStreet/Cobrand/BathNES.pm index 025648591..800ca88fa 100644 --- a/perllib/FixMyStreet/Cobrand/BathNES.pm +++ b/perllib/FixMyStreet/Cobrand/BathNES.pm @@ -96,8 +96,9 @@ sub default_show_name { 0 } sub default_map_zoom { 3 } sub map_js_extra { - my ($self, $c) = @_; + my $self = shift; + my $c = $self->{c}; return unless $c->user_exists; my $banes_user = $c->user->from_body && $c->user->from_body->areas->{$self->council_area_id}; diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm index 676e721c2..37fc34057 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm @@ -67,6 +67,10 @@ sub to_body { # Front page statistics +sub _cache_timeout { + FixMyStreet->config('CACHE_TIMEOUT') // 3600; +} + sub recent_fixed { my $rs = shift; my $key = "recent_fixed:$site_key"; @@ -76,7 +80,7 @@ sub recent_fixed { state => [ FixMyStreet::DB::Result::Problem->fixed_states() ], lastupdate => { '>', \"current_timestamp-'1 month'::interval" }, } )->count; - Memcached::set($key, $result, 3600); + Memcached::set($key, $result, _cache_timeout()); } return $result; } @@ -90,7 +94,7 @@ sub number_comments { { 'comments.state' => 'confirmed' }, { join => 'comments' } )->count; - Memcached::set($key, $result, 3600); + Memcached::set($key, $result, _cache_timeout()); } return $result; } @@ -105,7 +109,7 @@ sub recent_new { state => [ FixMyStreet::DB::Result::Problem->visible_states() ], confirmed => { '>', \"current_timestamp-'$interval'::interval" }, } )->count; - Memcached::set($key, $result, 3600); + Memcached::set($key, $result, _cache_timeout()); } return $result; } @@ -157,7 +161,7 @@ sub _recent { $probs = [ grep { $_->photo && ! $_->is_hidden } @$probs ]; } else { $probs = [ $rs->search( $query, $attrs )->all ]; - Memcached::set($key, $probs, 3600); + Memcached::set($key, $probs, _cache_timeout()); } } diff --git a/templates/web/base/admin/extra-metadata-form.html b/templates/web/base/admin/extra-metadata-form.html index 9264d98d9..4fc5d8e3f 100644 --- a/templates/web/base/admin/extra-metadata-form.html +++ b/templates/web/base/admin/extra-metadata-form.html @@ -12,7 +12,7 @@ <div class="admin-hint"><p>[% loc('Whether the field is displayed to the user, included as a hidden field and automatically populated, or set by the server upon Open311 submission. This field is usually set automatically.') %]</p></div> <label> [% loc('Automated') %] - <select name="metadata[[% loop.index %]].automated" data-field-name="automated" class="js-metadata-item-type"> + <select name="metadata[[% loop.index %]].automated" data-field-name="automated"> <option value="" [% meta.automated == '' ? 'selected' : '' %]></option> <option value="server_set" [% meta.automated == 'server_set' ? 'selected' : '' %]>[% loc('Server Set') %]</option> <option value="hidden_field" [% meta.automated == 'hidden_field' ? 'selected' : '' %]>[% loc('Hidden Field') %]</option> diff --git a/templates/web/base/common_header_tags.html b/templates/web/base/common_header_tags.html index 21081246d..e29d96655 100644 --- a/templates/web/base/common_header_tags.html +++ b/templates/web/base/common_header_tags.html @@ -38,7 +38,7 @@ <link rel="prefetch" href="[% version('/cobrands/fixmystreet/fixmystreet.js') %]"> [% END %] [% IF NOT bodyclass.match('mappage') %] - [% FOR script IN map_js.merge(c.cobrand.call_hook('map_js_extra', c)) %] + [% FOR script IN map_js.merge(c.cobrand.call_hook('map_js_extra')) %] <link rel="prefetch" href="[% IF script.match('^/'); version(script); ELSE; script; END %]"> [% END %] <link rel="prefetch" href="[% version('/cobrands/fixmystreet/map.js') %]"> diff --git a/templates/web/base/common_scripts.html b/templates/web/base/common_scripts.html index ac66aad46..fd7011763 100644 --- a/templates/web/base/common_scripts.html +++ b/templates/web/base/common_scripts.html @@ -47,7 +47,7 @@ IF c.user_exists AND (c.user.from_body OR c.user.is_superuser); END; IF bodyclass.match('mappage'); - FOR script IN map_js.merge(c.cobrand.call_hook('map_js_extra', c)); + FOR script IN map_js.merge(c.cobrand.call_hook('map_js_extra')); IF script.match('^/'); scripts.push(version(script)); ELSE; diff --git a/templates/web/fixmystreet-uk-councils/footer_extra_js.html b/templates/web/fixmystreet-uk-councils/footer_extra_js.html index 1742a55e2..76451344b 100644 --- a/templates/web/fixmystreet-uk-councils/footer_extra_js.html +++ b/templates/web/fixmystreet-uk-councils/footer_extra_js.html @@ -1,5 +1,12 @@ [% scripts.push( - version('/vendor/OpenLayers.Projection.OrdnanceSurvey.js') version('/cobrands/fixmystreet-uk-councils/js.js'), - version('/cobrands/highways/assets.js'), ) %] +[%~ +IF bodyclass.match('mappage'); + scripts.push( + version('/vendor/OpenLayers.Projection.OrdnanceSurvey.js'), + version('/cobrands/fixmystreet/assets.js'), + version('/cobrands/highways/assets.js'), + ); +END +%] diff --git a/templates/web/oxfordshire/footer_extra_js.html b/templates/web/oxfordshire/footer_extra_js.html index d95ed2c8e..24ec8486a 100644 --- a/templates/web/oxfordshire/footer_extra_js.html +++ b/templates/web/oxfordshire/footer_extra_js.html @@ -1,8 +1,12 @@ -[% scripts.push( +[% +IF bodyclass.match('mappage'); + scripts.push( version('/cobrands/fixmystreet/assets.js'), version('/vendor/OpenLayers.Projection.OrdnanceSurvey.js'), version('/cobrands/oxfordshire/js.js'), version('/cobrands/oxfordshire/assets.js'), version('/cobrands/highways/assets.js'), version('/cobrands/fixmystreet-uk-councils/council_validation_rules.js'), -) %] + ); +END; +%] diff --git a/web/cobrands/fixmystreet/admin.js b/web/cobrands/fixmystreet/admin.js index 3066ee614..c40a7f960 100644 --- a/web/cobrands/fixmystreet/admin.js +++ b/web/cobrands/fixmystreet/admin.js @@ -165,7 +165,7 @@ $(function(){ function renumber_metadata_fields($item) { var item_index = $item.data("index"); - $item.find("input[data-field-name").each(function(i) { + $item.find("[data-field-name]").each(function(i) { var $input = $(this); var prefix = "metadata["+item_index+"]."; var name = prefix + $input.data("fieldName"); |