Sha256: fd1096fe7e5b54e9be78268cbf27f39d004e798e5eb65102e1ff8fe3802f874a

Contents?: true

Size: 1.81 KB

Versions: 7

Compression:

Stored size: 1.81 KB

Contents

migrate

seed do
  500.times do
    d = Dummy.create string: 'zomgstring', number: [999,777].sample, text: 'zomgtext'

    2.times do
      f = Fluffy.create string: 'zomgstring', number: [999,777].sample, text: 'zomgtext', dummy_id: d.id
      b = Bobby.create string: 'zomgstring', number: [999,777].sample, text: 'zomgtext', dummy_id: d.id
      l = Loony.create string: 'zomgstring', fluffy_id: f.id
    end
  end
end

activate do
  Dummy.instance_eval do
    protect do
      scope { where }
      can :read, :string
    end
  end

  Fluffy.instance_eval do
    protect do
      scope { where }
      can :read
    end
  end

  # Define attributes methods
  Dummy.first
end

benchmark 'Read from unprotected model (100k)' do
  d = Dummy.first
  100_000.times { d.string }
end

benchmark 'Read open field (100k)' do
  d = Dummy.first
  d = d.restrict!('!') if activated?
  100_000.times { d.string }
end

benchmark 'Read nil field (100k)' do
  d = Dummy.first
  d = d.restrict!('!') if activated?
  100_000.times { d.text }
end

benchmark 'Check existance' do
  scope = activated? ? Dummy.restrict!('!') : Dummy.where
  1000.times { scope.any? }
end

benchmark 'Count' do
  scope = Dummy.limit(1)
  scope = scope.restrict!('!') if activated?
  1000.times { scope.count }
end

benchmark 'Select one' do
  scope = Dummy.limit(1)
  scope = scope.restrict!('!') if activated?
  1000.times { scope.to_a }
end

benchmark 'Select many' do
  scope = Dummy.where
  scope = scope.restrict!('!') if activated?
  200.times { scope.to_a }
end

benchmark 'Select with eager loading' do
  scope = Dummy.eager(:fluffies)
  scope = scope.restrict!('!') if activated?
  200.times { scope.to_a }
end

benchmark 'Select with filtered eager loading' do
  scope = Dummy.eager_graph(fluffies: :loony)
  scope = scope.restrict!('!') if activated?
  200.times { scope.to_a }
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
protector-0.7.7 perf/sequel_perf.rb
protector-0.7.6 perf/sequel_perf.rb
protector-0.7.4 perf/sequel_perf.rb
protector-0.7.3 perf/sequel_perf.rb
protector-0.7.2 perf/sequel_perf.rb
protector-0.7.1 perf/sequel_perf.rb
protector-0.7.0 perf/sequel_perf.rb