Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
epugh committed Jan 24, 2024
1 parent 1554fe8 commit 37e9135
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 17 deletions.
4 changes: 2 additions & 2 deletions app/controllers/api/v1/books/populate_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ class PopulateController < Api::ApiController
# We get a messy set of params in this method, so we don't use the normal
# approach of strong parameter validation. We hardcode the only params
# we care about.
#
#
# With 5000 queries in large case, this takes 108 seconds...
#
#
# rubocop:disable Layout/LineLength
def update
puts "[PopulateController] Request Size is #{number_to_human_size(query_doc_pairs_params.to_s.bytesize)}"
Expand Down
16 changes: 10 additions & 6 deletions app/controllers/api/v1/snapshots_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def authenticate_api!
def index
@snapshots = @case.snapshots

@shallow = params[:shallow] == 'true'
@shallow = 'true' == params[:shallow]
@with_docs = false

respond_with @snapshots
Expand All @@ -34,31 +34,35 @@ def show
end

# rubocop:disable Metrics/MethodLength
# rubocop:disable Metrics/AbcSize
# rubocop:disable Layout/LineLength
def create
@snapshot = @case.snapshots.build(name: params[:snapshot][:name])
@snapshot.scorer = @case.scorer
@snapshot.try = @case.tries.first

if @snapshot.save

serialized_data = Marshal.dump(snapshot_params)

puts "[SnapshotController] the size of the serialized data is #{number_to_human_size(serialized_data.bytesize)}"
compressed_data = Zlib::Deflate.deflate(serialized_data)
puts "[SnapshotController] the size of the compressed data is #{number_to_human_size(compressed_data.bytesize)}"
@snapshot.snapshot_file.attach(io: StringIO.new(compressed_data), filename: "snapshot_#{@snapshot.id}.bin.zip",
content_type: 'application/zip')
PopulateSnapshotJob.perform_later @snapshot
content_type: 'application/zip')
PopulateSnapshotJob.perform_later @snapshot

Analytics::Tracker.track_snapshot_created_event current_user, @snapshot

@with_docs = false # don't show individual docs in the response
respond_with @snapshot
else
render json: @snapshot.errors, status: :bad_request
end
end
# rubocop:enable Metrics/MethodLength
# rubocop:enable Metrics/AbcSize
# rubocop:enable Layout/LineLength

def destroy
@snapshot.destroy
Expand All @@ -79,7 +83,7 @@ def set_snapshot
def check_snapshot
render json: { error: 'Not Found!' }, status: :not_found unless @snapshot
end

def snapshot_params
# avoid StrongParameters ;-( to faciliate sending params as
# hash to ActiveJob via ActiveStorage by directly getting parameters from request
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def index

def new
@user = User.new

if Rails.env.production? && Rails.application.config.devise.omniauth_providers.include?(:google_oauth2)
# Google only lets us oAuth from https sites in production.
@flag_not_on_https = false
Expand Down
7 changes: 1 addition & 6 deletions app/jobs/populate_snapshot_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ class PopulateSnapshotJob < ApplicationJob
sidekiq_options log_level: :warn

# rubocop:disable Security/MarshalLoad
# rubocop:disable Metrics/MethodLength
# rubocop:disable Metrics/AbcSize
def perform snapshot
# down the road we should be using ActiveRecord-import and first_or_initialize instead.
# See how snapshots are managed.
Expand All @@ -23,12 +21,9 @@ def perform snapshot
snapshot_queries = params[:snapshot][:queries]

service.add_docs snapshot_docs, snapshot_queries if snapshot_docs

snapshot.snapshot_file.purge
snapshot.save

end
# rubocop:enable Security/MarshalLoad
# rubocop:enable Metrics/MethodLength
# rubocop:enable Metrics/AbcSize
end
2 changes: 1 addition & 1 deletion app/models/snapshot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Snapshot < ApplicationRecord
has_many :snapshot_queries, dependent: :destroy
has_many :snapshot_docs,
through: :snapshot_queries

has_one_attached :snapshot_file

# Validations
Expand Down
4 changes: 3 additions & 1 deletion test/integration/experiment_with_bulk_insert_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ class ExperimentWithBulkInsertTest < ActionDispatch::IntegrationTest
let(:scorer) { scorers(:quepid_default_scorer) }
let(:selection_strategy) { selection_strategies(:multiple_raters) }

# rubocop:disable Style/ClassVars
@@skip_tests = true

# rubocop:enable Style/ClassVars

test 'generate and export 5000 queries with traditional AR' do
skip('Ignoring all tests in ExperimentWithBulkInsertTest') if @@skip_tests
book = user.books.create name: '50000 Query Doc Pairs', scorer: scorer, selection_strategy: selection_strategy
Expand Down

0 comments on commit 37e9135

Please sign in to comment.