3 ms·
> It turns out it was coming from this line in my model. > This innocuous little line was responsible for 80% of > my total database load. This validates call i
by petergeoghegan 9y ago
> It turns out it was coming from this line in my model.
> This innocuous little line was responsible for 80% of
> my total database load. This validates call is Rails
> attempting to ensure that no two Repo records get
> created with the same username and name. Instead of
> enforcing the consistency in the database, it put a
> before commit hook onto the object and it’s querying
> the database before we create a new repo to make sure
> there aren’t any duplicates.
I still can't believe that Rails even attempts this. It's simply not possible to do this kind of enforcement in a race-free manner using SELECT statements with Postgres.