# Autobot plugin - Duplicate posts problem

**URL:** <https://meta.discourse.org/t/autobot-plugin-duplicate-posts-problem/74806>\
**Category:** Product Support\
**Created:** [November 12, 2017, 3:27pm UTC](https://meta.discourse.org/t/autobot-plugin-duplicate-posts-problem/74806 "2017-11-12T15:27:09Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![schungx](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/schungx/32/70989_2.png) [@schungx](https://meta.discourse.org/u/schungx)\
**Post date:** [November 21, 2017, 3:55pm UTC](https://meta.discourse.org/t/autobot-plugin-duplicate-posts-problem/74806/3 "2017-11-21T15:55:39Z")

</div>

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

> <https://github.com/vinkashq/discourse-autobot/blob/master/lib/autobot/post_creator.rb#L111>

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.

---

_[View the full topic](https://meta.discourse.org/t/autobot-plugin-duplicate-posts-problem/74806)._
