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
..
2018-09-21 11:02:23 +00:00
2018-06-07 13:28:18 +08:00
2018-12-04 10:48:16 +01:00
2018-02-26 10:25:58 +11:00
2018-04-25 08:44:07 +10:00
2018-06-07 13:28:18 +08:00
2018-04-18 11:32:32 +05:30
2018-06-07 13:28:18 +08:00
2018-08-10 11:34:01 +10:00
2019-01-14 17:03:18 -05:00