Skip to content

Commit

Permalink
Fix bugs in profiling scripts leading to incorrect results.
Browse files Browse the repository at this point in the history
  • Loading branch information
tgxworld committed Sep 13, 2017
1 parent e70428a commit 26c6447
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
6 changes: 2 additions & 4 deletions app/models/user.rb
Expand Up @@ -693,14 +693,12 @@ def activate
if email_token = self.email_tokens.active.where(email: self.email).first
EmailToken.confirm(email_token.token)
else
self.active = true
save
self.update!(active: true)
end
end

def deactivate
self.active = false
save
self.update!(active: false)
end

def change_trust_level!(level, opts = nil)
Expand Down
10 changes: 8 additions & 2 deletions script/bench.rb
Expand Up @@ -188,7 +188,7 @@ def bench(path, name)
append = "?api_key=#{api_key}&api_username=admin1"

# asset precompilation is a dog, wget to force it
run "wget http://127.0.0.1:#{@port}/ -O /dev/null"
run "wget http://127.0.0.1:#{@port}/ -o /dev/null -O /dev/null"

tests = [
["categories", "/categories"],
Expand All @@ -197,7 +197,13 @@ def bench(path, name)
# ["user", "/u/admin1/activity"],
]

tests = tests.map { |k, url| ["#{k}_admin", "#{url}#{append}"] } + tests
tests.concat(tests.map { |k, url| ["#{k}_admin", "#{url}#{append}"] })

tests.each do |_, path|
if `curl -s -I "http://127.0.0.1:#{@port}#{path}"` !~ /200 OK/
raise "#{path} returned non 200 response code"
end
end

# NOTE: we run the most expensive page first in the bench

Expand Down
4 changes: 2 additions & 2 deletions script/profile_db_generator.rb
Expand Up @@ -46,10 +46,10 @@ def create_admin(seq)
admin.email = "admin@localhost#{seq}.fake"
admin.username = "admin#{seq}"
admin.password = "password"
admin.save
admin.save!
admin.grant_admin!
admin.change_trust_level!(TrustLevel[4])
admin.email_tokens.update_all(confirmed: true)
admin.activate
}
end

Expand Down

1 comment on commit 26c6447

@discoursebot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/when-should-discourse-upgrade-to-rails-5/67123/24

Please sign in to comment.