pluto-models 1.5.0 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ad263401c798a7b1d893eb500232872a8afc0ca8
4
- data.tar.gz: 1a49217497e1b15de32024bdc53fcef480bf0195
3
+ metadata.gz: b81d3634465206e2bac108bcff1629627a250fd0
4
+ data.tar.gz: c5b02063eb4ac615fd6e2be6fef55847a24be435
5
5
  SHA512:
6
- metadata.gz: 11ff9b19fbe322bd20748edc5f6ce993b0235565c9501a2db45ce67d74f2655596d09a937162d1a98060d4129114cea3b03f6a685bd46d79da0270f1e5eaf889
7
- data.tar.gz: b88a9638733715423053eeae0e81dde8d622d34c087e767ee6480c8108da1bd6b102dae3dd70c60db709abc1c94625c49f9f074bd8dbc98d5e7a6fd62c7123c2
6
+ metadata.gz: c925c6718b7ee40814b4bda67fb99fb19347adc5cba20a030ea1dcddb1d48311050cc3c358e77e103459c9fc650aa38641ea3c6200b32eb03e2d7497e9944264
7
+ data.tar.gz: 61364d47455fca58c1cc02282d712f846df860162a1455327c774ce73e6cd73af9545f2f5c2fad5effa7b0519e6e192d13302f9e80af29c8b1f56a12665d911d
@@ -14,6 +14,7 @@ lib/pluto/schema.rb
14
14
  lib/pluto/version.rb
15
15
  test/data/ruby.ini
16
16
  test/helper.rb
17
+ test/test_delete_removed.rb
17
18
  test/test_filter.rb
18
19
  test/test_helpers.rb
19
20
  test/test_site.rb
@@ -125,6 +125,37 @@ class Feed < ActiveRecord::Base
125
125
  end # each item
126
126
 
127
127
 
128
+ ###
129
+ # delete (old) feed items if no longer in feed AND
130
+ # date range is in (lastest/current) feed list
131
+ #
132
+ # thanks to Harry Wood
133
+ # see https://github.com/feedreader/pluto/pull/16
134
+ # for more comments
135
+
136
+ #
137
+ # todo/fix: use a delete feature/command line flag to make it optional - why? why not?
138
+
139
+
140
+ guids_in_feed = data.items.map {|item| item.guid}
141
+ earliest_still_in_feed = data.items.min_by(&:published).published
142
+
143
+ items_no_longer_present =
144
+ Item
145
+ .where(feed_id: id)
146
+ .where.not(published: nil)
147
+ .where("published > ?", earliest_still_in_feed)
148
+ .where.not(guid: guids_in_feed)
149
+
150
+ unless items_no_longer_present.empty?
151
+ logger.info "#{items_no_longer_present.size} items no longer present in the feed (presumed removed at source). Deleting from pluto db"
152
+ items_no_longer_present.each do |item|
153
+ logger.info "** DELETE | #{item.title}"
154
+ item.destroy
155
+ end
156
+ end
157
+
158
+
128
159
  # update cached value last published for item
129
160
  ## todo/check: force reload of items - why? why not??
130
161
  last_item_rec = items.latest.limit(1).first # note limit(1) will return relation/arrar - use first to get first element or nil from ary
@@ -4,7 +4,7 @@ module Pluto
4
4
 
5
5
  MAJOR = 1
6
6
  MINOR = 5
7
- PATCH = 0
7
+ PATCH = 1
8
8
  VERSION = [MAJOR,MINOR,PATCH].join('.')
9
9
 
10
10
  def self.version
@@ -0,0 +1,66 @@
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_delete_removed.rb
6
+ # or better
7
+ # rake test
8
+
9
+ require 'helper'
10
+
11
+ class TestDeleteRemoved < MiniTest::Test
12
+
13
+ def test_delete_removed
14
+
15
+ feed = Feed.create!(
16
+ key: 'test',
17
+ title: 'Feed title'
18
+ )
19
+
20
+ feed_data = FeedParser::Feed.new
21
+ feed_data.title = 'Feed data title'
22
+ feed_data.items = []
23
+
24
+ item_data = FeedParser::Item.new
25
+ item_data.guid = 'https://myblog.com/?p=1113'
26
+ item_data.title = 'Good post #3'
27
+ item_data.published = Time.now
28
+ feed_data.items << item_data
29
+
30
+ item_data = FeedParser::Item.new
31
+ item_data.guid = 'https://myblog.com/?p=1112'
32
+ item_data.title = 'Spam post #2'
33
+ item_data.published = Time.now - 10.minutes
34
+ feed_data.items << item_data
35
+
36
+ item_data = FeedParser::Item.new
37
+ item_data.guid = 'https://myblog.com/?p=1111'
38
+ item_data.title = 'Good post #1'
39
+ item_data.published = Time.now - 20.minutes
40
+
41
+ feed_data.items << item_data
42
+
43
+ feed.deep_update_from_struct!( feed_data )
44
+
45
+ assert_equal(3, Item.count)
46
+
47
+
48
+ feed_data.items = []
49
+
50
+ item_data = FeedParser::Item.new
51
+ item_data.guid = 'https://myblog.com/?p=1113'
52
+ item_data.title = 'Good post #2'
53
+ item_data.published = Time.now
54
+ feed_data.items << item_data
55
+
56
+ item_data = FeedParser::Item.new
57
+ item_data.guid = 'https://myblog.com/?p=1111'
58
+ item_data.title = 'Good post #1'
59
+ item_data.published = Time.now - 20.minutes
60
+ feed_data.items << item_data
61
+
62
+ feed.deep_update_from_struct!( feed_data )
63
+
64
+ assert_equal(2, Item.count)
65
+ end
66
+ end # class TestDeleteRemoved
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pluto-models
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-27 00:00:00.000000000 Z
11
+ date: 2019-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: props
@@ -203,6 +203,7 @@ files:
203
203
  - lib/pluto/version.rb
204
204
  - test/data/ruby.ini
205
205
  - test/helper.rb
206
+ - test/test_delete_removed.rb
206
207
  - test/test_filter.rb
207
208
  - test/test_helpers.rb
208
209
  - test/test_site.rb