Skip to content

Commit

Permalink
fixed duplicated operations in PLCImporter fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
mackuba committed Aug 19, 2024
1 parent 3ee0c43 commit 3f2885d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/didkit/plc_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ def initialize(since: nil)
@last_date = Time.now
@eof = true
end

@last_page_cids = []
end

def plc_service
Expand Down Expand Up @@ -57,16 +59,22 @@ def fetch_page
query = @last_date ? { :after => @last_date.utc.iso8601(6) } : {}
rows = get_export(query)

operations = rows.filter_map do |json|
operations = rows.filter_map { |json|
begin
PLCOperation.new(json)
rescue PLCOperation::FormatError, AtHandles::FormatError, ServiceRecord::FormatError => e
@error_handler ? @error_handler.call(e, json) : raise
nil
end
end
}.reject { |op|
# when you pass the most recent op's timestamp to ?after, it will be returned as the first op again,
# so we need to use this CID list to filter it out (so pages will usually be 999 items long)

@last_page_cids.include?(op.cid)
}

@last_date = operations.last&.created_at || request_time
@last_page_cids = Set.new(operations.map(&:cid))
@eof = (rows.length < MAX_PAGE)

operations
Expand Down

0 comments on commit 3f2885d

Please sign in to comment.