The `posts` relation on `Topic` is not ordered. Using `Topic.posts.first` is basically the same as asking for a random post, it will depend on DB order. This breaks on Topic merge and split for example. Additionally, a huge problem with that is that it forces active record down a slow path. `Topic.posts.first` is extremely slow on giant topics, since it has no default ordering it appears AR materializes the entire set prior to doing `first`. This commit also illustrates the importance of testing, initially I only fixed the second instance of the problem in `post_validator.rb` but testing revealed that the problem was repeated at the top of the file. Longer term we should consider a larger change of default ordering the posts relations so people do not fall down this trap anymore. |
||
|---|---|---|
| .. | ||
| components | ||
| fabricators | ||
| fixtures | ||
| helpers | ||
| import_export | ||
| integration | ||
| integrity | ||
| jobs | ||
| lib | ||
| mailers | ||
| models | ||
| multisite | ||
| requests | ||
| serializers | ||
| services | ||
| support | ||
| tasks | ||
| views/omniauth_callbacks | ||
| rails_helper.rb | ||