Autobot plugin - Duplicate posts problem

I am wondering, if a post created by the autobot is DELETED, then what happens?

Notice the use of first here – it finds the first post with the correct feed item url. Why the first one? Shouldn’t it be the LAST one at least? And shouldn’t the list be sorted (say order(:post_id)) before taking first or last so it is at least predictable?

Since the post custom fields are never deleted together with the post, this almost means that the deleted first post will be found every time. Mostly like meaning that try(:post) will return nil and then a new post gets created EVERY TIME the RSS feed is scanned.

This, I believe, is the reason behind all those duplicated posts.

Shouldn’t the correct behavior be to:

  1. First sort the posts by post_id (same as by date)
  2. Filter out all the deleted posts
  3. Take the last one

I would have made a PR if I know how to… but I’m not too comfortable with all those ActiveRecord stuff.