Don't forget to lycansubscribe

fix for possible duplicated posts in one batch

Changed files
+8 -11
app
+8 -11
app/post_downloader.rb
··· 51 51 response = @sky.get_request('app.bsky.feed.getPosts', { uris: items.map(&:post_uri).uniq }) 52 52 53 53 response['posts'].each do |data| 54 - begin 55 - item = items.detect { |x| x.post_uri == data['uri'] } 56 - items.delete(item) 54 + current_items = items.select { |x| x.post_uri == data['uri'] } 55 + items -= current_items 57 56 57 + begin 58 58 post = save_post(data['uri'], data['record']) 59 59 60 60 if post.valid? 61 - update_item(item, post) 61 + current_items.each { |i| update_item(i, post) } 62 62 else 63 - puts "Invalid post #{item.post_uri}: #{post.errors.full_messages.join("; ")}" 64 - invalidate_item(item) 63 + puts "Invalid post #{data['uri']}: #{post.errors.full_messages.join("; ")}" 64 + current_items.each { |i| invalidate_item(i) } 65 65 end 66 66 rescue InvalidRecordError => e 67 - puts "Error in PostDownloader: #{item.post_uri}: #{e.class}: #{e}" 68 - 69 - item = items.detect { |x| x.post_uri == data['uri'] } 70 - item.update!(queue: nil) 71 - items.delete(item) 67 + puts "Error in PostDownloader: #{data['uri']}: #{e.class}: #{e}" 68 + current_items.each { |i| i.update!(queue: nil) } 72 69 end 73 70 end 74 71