Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions lib/simple_captcha/simple_captcha_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@ def get_data(key)
end

def remove_data(key)
where(["#{connection.quote_column_name(:key)} = ?", key]).delete_all
clear_old_data(1.hour.ago)
begin
where(["#{connection.quote_column_name(:key)} = ?", key]).delete_all
clear_old_data(1.hour.ago)
rescue StandardError => err
Rails.logger.error "#{err.class} #{err.message}"
end
end

def clear_old_data(time = 1.hour.ago)
return unless Time === time
where(["#{connection.quote_column_name(:updated_at)} < ?", time]).delete_all
rescue ActiveRecord::Deadlocked => err
rescue StandardError => err
Rails.logger.error "#{err.class} #{err.message}"
end
end
Expand Down