Method: Unread::GarbageCollector#run!

Defined in:
lib/unread/garbage_collector.rb

#run!Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/unread/garbage_collector.rb', line 8

def run!
  ReadMark.reader_classes.each do |reader_class|
    readers_to_cleanup(reader_class).find_each do |reader|
      if oldest_timestamp = readable_class.read_scope(reader).
                              unread_by(reader).
                              minimum(readable_class.readable_options[:on])
        # There are unread items, so update the global read_mark for this reader to the oldest
        # unread item and delete older read_marks
        update_read_marks_for_user(reader, oldest_timestamp)
      else
        # There is no unread item, so deletes all markers and move global timestamp
        readable_class.reset_read_marks_for_user(reader)
      end
    end
  end
end