Pivotal Labs

Main menu

Skip to primary content
Skip to secondary content
  • About
  • Case Studies
  • Team
    • Executives
    • Locations
      • San Francisco (HQ)
      • Boston
      • Boulder
      • Denver
      • London
      • Los Angeles
      • New York
  • Community
    • Blogs
    • Tech Talks
    • Events
  • Careers
    • Lifestyle
    • Principles & Practices
    • Benefits
    • FAQ
    • Apply
  • Contact
    • Press Room
    • Press Releases
    • In The News
    • Press Kit
  • All
  • Labs
  • Standup
  • Tracker

Gemnasium offers you Security/Steroids

Kris Kelly
Tuesday, February 26, 2013

Interestings

Security on Steroids

The list of security monitoring services continues to grow. In addition to the holepicker gem and the private beta code climate service, Gemnasium is now offering "Security on Steroids."

http://sendgrid.com/wf/webmail?rp=ZTI1bGQzTnNaWFIwWlhKZmFXUTZNVEl6TkN4MWMyVnlYMmxrT2pJMU5qVTBmUWV5SnVaWGR6YkdWMGRHVnlYMmxrSWpvaU1USXdOamc1TUNJc0ltNWxkM05zWlhSMFpYSmZkWE5sY2w5cFpDSTZNVFV3TVRneE1EZzNOREo5

  • 0 Shares
  • Share on Facebook
  • Share on Twitter

07/27/12: ActiveRecord.count changes your select

Kris Kelly
Friday, July 27, 2012

Interestings

  • Chrome slow after click on body

While investigating memory leaks in a single page JS app, we found that rendering times increased by ~2 seconds after clicking on the body of the document.

It only happens in Chrome, Webkit and Firefox don’t have the problem.

We don’t seem to have any click handlers that fire when clicking on the body.

  • Putting .count on the end of an ActiveRecord query blows away your select

Here’s a scope for customers who have at least one subscription:

Customer.select(’DISTINCT customers.*’).joins(:subscriptions).where(”subscriptions.customer_id IS NOT NULL”)

This produces the following SQL:

SELECT DISTINCT customers.* FROM “customers” INNER JOIN “subscriptions” ON “subscriptions”.”customer_id” = “customers”.”id” WHERE (subscriptions.customer_id IS NOT NULL)

Say you want to know how many of these there are. If you put .count on the end of the scope, it converts the SQL to this:

SELECT COUNT(*) FROM “customers” INNER JOIN “subscriptions” ON “subscriptions”.”customer_id” = “customers”.”id” WHERE (subscriptions.customer_id IS NOT NULL)

It loses the distinct, so the query returns a customer object for each subscription. This means that if a customer has 2 subscriptions, they appear twice in the result set.

Workaround:

Using length instead of count works. It executes the query and then counts the number of results. There seems to be no easy way to do a count query that is not count(*).

This is a known bug in rails that has been patched, but not yet released:

https://github.com/rails/rails/issues/5554

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Kris Kelly

Kris Kelly
San Francisco

Subscribe to Kris's Feed

Author Topics

agile (1)
Ideas (1)
  • About
  • Case Studies
  • Team
  • Community
  • Careers
  • Contact
  • Labs
  • Events

Contact Us

contact@pivotallabs.com
+1 415-77-PIVOT
TwitterLinkedInFacebook

Pivotal Tracker

Tracker is the award-winning agile project management tool that enables real-time collaboration around a shared, prioritized backlog.
Visit pivotaltracker.com >