Skip to content
This repository was archived by the owner on Jan 24, 2025. It is now read-only.

Commit 7cbf8fc

Browse files
authored
Merge pull request #804 from alphagov/temp-up-max-deletions-fix-duplicates
Up the max deletions to fix duplicate datasets
2 parents 2ca4d70 + 8a773ad commit 7cbf8fc

17 files changed

+28
-33
lines changed

.rubocop.yml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ AllCops:
44
- bin/**/*
55
- config.ru
66
- db/schema.rb
7+
- db/migrate/*
78
- vendor/**/*
89
- lib/ckan/v26/depaginator.rb
910

app/controllers/application_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class ApplicationController < ActionController::Base
1717
private
1818

1919
def record_not_found
20-
render plain: '404 Not Found', status: 404
20+
render plain: '404 Not Found', status: :not_found
2121
end
2222

2323
def set_raven_context

app/controllers/datasets/licences_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def create
2020

2121
def update
2222
@dataset = current_dataset
23-
@dataset.update_attributes(params.require(:dataset).permit(:licence_code))
23+
@dataset.update(params.require(:dataset).permit(:licence_code))
2424

2525
if @dataset.save(context: :dataset_form)
2626
redirect_to dataset_path(@dataset.uuid, @dataset.name)

app/controllers/datasets/locations_controller.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def edit
1010
def create
1111
@dataset = current_dataset
1212
location_params = params.require(:dataset).permit(:location1, :location2, :location3)
13-
@dataset.update_attributes(location_params)
13+
@dataset.update(location_params)
1414

1515
if @dataset.save
1616
redirect_to new_dataset_frequency_path(@dataset.uuid, @dataset.name)
@@ -22,7 +22,7 @@ def create
2222
def update
2323
@dataset = current_dataset
2424
location_params = params.require(:dataset).permit(:location1, :location2, :location3)
25-
@dataset.update_attributes(location_params)
25+
@dataset.update(location_params)
2626

2727
if @dataset.save
2828
redirect_to dataset_path(@dataset.uuid, @dataset.name)

app/helpers/application_helper.rb

-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
module ApplicationHelper
2-
def url_contains(action)
3-
url = request.path
4-
url.gsub(@dataset.title, '') if @dataset.title
5-
url.include?(action)
6-
end
7-
82
def sortable(column, title = nil)
93
title ||= column.titleize
104
direction = column == sort_column && sort_direction == "asc" ? "desc" : "asc"

app/models/healthcheck/recurring_jobs/ckan_org_sync.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ def name
1313
end
1414

1515
def status
16-
if Time.parse(when_last_run) <= critical_latency
16+
if Time.zone.parse(when_last_run) <= critical_latency
1717
:critical
18-
elsif Time.parse(when_last_run) <= warning_latency
18+
elsif Time.zone.parse(when_last_run) <= warning_latency
1919
:warning
2020
else
2121
:ok

app/models/healthcheck/recurring_jobs/package_sync.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ def name
1313
end
1414

1515
def status
16-
if Time.parse(when_last_run) <= critical_latency
16+
if Time.zone.parse(when_last_run) <= critical_latency
1717
:critical
18-
elsif Time.parse(when_last_run) <= warning_latency
18+
elsif Time.zone.parse(when_last_run) <= warning_latency
1919
:warning
2020
else
2121
:ok

app/models/topic.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
class Topic < ApplicationRecord
2-
has_many :datasets
2+
has_many :datasets, dependent: :restrict_with_exception
33
end

app/services/index_deletion_service.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def run
2525
def select_indexes_for_deletion(indexes)
2626
ordered_indexes = indexes
2727
.select { |index_name| index_name.include? "#{index_alias}_" }
28-
.sort_by { |index_name| Time.parse(index_name.gsub(/"#{index_alias}_"/, '')) }
28+
.sort_by { |index_name| Time.zone.parse(index_name.gsub(/"#{index_alias}_"/, '')) }
2929
.reverse
3030

3131
# Ensure that the three most recent indexes are not deleted

config/application.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ class Application < Rails::Application
4040
html_tag
4141
}
4242

43-
config.autoload_paths += [Rails.root.join("app/workers")]
44-
config.autoload_paths += [Rails.root.join("lib/validators")]
45-
config.autoload_paths += [Rails.root.join("lib/ckan")]
43+
config.autoload_paths += [Rails.root.join("app", "workers")]
44+
config.autoload_paths += [Rails.root.join("lib", "validators")]
45+
config.autoload_paths += [Rails.root.join("lib", "ckan")]
4646

4747
config.elasticsearch = config_for(:elasticsearch)
4848
end

config/environments/development.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
config.consider_all_requests_local = true
1414

1515
# Enable/disable caching. By default caching is disabled.
16-
if Rails.root.join('tmp/caching-dev.txt').exist?
16+
if Rails.root.join('tmp', 'caching-dev.txt').exist?
1717
config.action_controller.perform_caching = true
1818

1919
config.cache_store = :memory_store

config/initializers/elasticsearch.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def es_config_from_vcap
66
Rails.logger.fatal "Failed to extract ES creds from VCAP_SERVICES. Exiting"
77
Rails.logger.fatal Rails.configuration.elasticsearch['vcap_services']
88
Rails.logger.fatal e
9-
exit
9+
return
1010
end
1111

1212
es_config_from_host(es_server)

lib/ckan/v26/depaginator.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module V26
55
class Depaginator
66
include CKAN::Modules::URLBuilder
77

8-
MAX_DELETIONS = 100
8+
MAX_DELETIONS = 1500
99

1010
def self.depaginate(*args)
1111
self.new(*args).depaginate

lib/tasks/search.rake

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace :search do
44
batch_size = args.batch_size.nil? ? 50 : args.batch_size.to_i
55
logger = Rails.logger
66
client = Dataset.__elasticsearch__.client
7-
date = Time.now.strftime('%Y%m%d%H%M%S')
7+
date = Time.zone.now.strftime('%Y%m%d%H%M%S')
88
index_alias = ENV['ES_INDEX'] || "datasets-#{Rails.env}"
99
legacy_index = index_alias
1010
new_index_name = "#{Dataset.index_name}_#{date}"

spec/features/ckan_v26_package_sync_spec.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
legacy_name: "dataset_to_reimport",
2222
uuid: search_dataset_p1["results"][3]["id"],
2323
status: "draft",
24-
updated_at: Time.parse(search_dataset_p1["results"][3]["metadata_modified"]),
24+
updated_at: Time.zone.parse(search_dataset_p1["results"][3]["metadata_modified"]),
2525
)
2626
}
2727

@@ -34,7 +34,7 @@
3434
let!(:dataset_not_to_update) do
3535
create :dataset, legacy_name: "dataset_not_to_update",
3636
uuid: dataset_not_to_update_id,
37-
updated_at: Time.now
37+
updated_at: Time.zone.now
3838
end
3939

4040
before do
@@ -70,14 +70,14 @@
7070
it 'updates existing datasets when they change in ckan' do
7171
expect { subject.perform }
7272
.to change { dataset_to_update.reload.updated_at }
73-
.to(Time.parse(package_show_update["result"]["metadata_modified"]))
73+
.to(Time.zone.parse(package_show_update["result"]["metadata_modified"]))
7474
end
7575

7676
it "updates existing datasets when they're draft but appear in CKAN" do
7777
subject.perform
7878
dataset_to_reimport.reload
7979

80-
expect(dataset_to_reimport.updated_at).to eq(Time.parse(package_show_update["result"]["metadata_modified"]))
80+
expect(dataset_to_reimport.updated_at).to eq(Time.zone.parse(package_show_update["result"]["metadata_modified"]))
8181
expect(dataset_to_reimport.status).to eq("published")
8282
end
8383

spec/features/dataset_create_spec.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -361,28 +361,28 @@ def pick_quarter(quarter)
361361
fill_in 'datafile[url]', with: 'https://localhost/doc'
362362
fill_in 'datafile[name]', with: 'my test doc'
363363
choose option: quarter.to_s
364-
fill_in "datafile[year]", with: Date.today.year
364+
fill_in "datafile[year]", with: Time.zone.today.year
365365
click_button "Save and continue"
366366
end
367367

368368
it "calculates correct dates for Q1" do
369369
pick_quarter(1)
370-
expect(Dataset.last.datafiles.last.end_date).to eq(Date.new(Date.today.year, 6).end_of_month)
370+
expect(Dataset.last.datafiles.last.end_date).to eq(Date.new(Time.zone.today.year, 6).end_of_month)
371371
end
372372

373373
it "calculates correct dates for Q2" do
374374
pick_quarter(2)
375-
expect(Dataset.last.datafiles.last.end_date).to eq(Date.new(Date.today.year, 9).end_of_month)
375+
expect(Dataset.last.datafiles.last.end_date).to eq(Date.new(Time.zone.today.year, 9).end_of_month)
376376
end
377377

378378
it "calculates correct dates for Q3" do
379379
pick_quarter(3)
380-
expect(Dataset.last.datafiles.last.end_date).to eq(Date.new(Date.today.year, 12).end_of_month)
380+
expect(Dataset.last.datafiles.last.end_date).to eq(Date.new(Time.zone.today.year, 12).end_of_month)
381381
end
382382

383383
it "calculates correct dates for Q4" do
384384
pick_quarter(4)
385-
expect(Dataset.last.datafiles.last.end_date).to eq(Date.new(Date.today.year, 3).end_of_month + 1.year)
385+
expect(Dataset.last.datafiles.last.end_date).to eq(Date.new(Time.zone.today.year, 3).end_of_month + 1.year)
386386
end
387387
end
388388

spec/rails_helper.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
# directory. Alternatively, in the individual `*_spec.rb` files, manually
2424
# require only the support files necessary.
2525
#
26-
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
26+
Dir[Rails.root.join('spec', 'support', '**', '*.rb')].each { |f| require f }
2727

2828
# Checks for pending migration and applies them before tests are run.
2929
# If you are not using ActiveRecord, you can remove this line.

0 commit comments

Comments
 (0)