Sam a7628c1d74 FIX: use ordered_posts for last post check, not the posts relation
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.
2019-01-18 13:18:40 +11:00
..
2019-01-16 15:01:50 -05:00
2017-07-28 10:20:09 +09:00
2018-01-30 08:54:37 +11:00
2017-07-28 10:20:09 +09:00
2017-07-28 10:20:09 +09:00
2018-07-05 15:34:58 +10:00
2018-04-18 11:32:32 +05:30
2018-08-27 14:50:56 +10:00