Class: ImageDuplicateFinderWorker
- Inherits:
-
Object
- Object
- ImageDuplicateFinderWorker
- Includes:
- Sidekiq::Worker, Workers::StatusBroadcastable
- Defined in:
- app/workers/image_duplicate_finder_worker.rb
Overview
Background worker that finds duplicate images using pHash fingerprints.
Results are stored in the image_duplicate_pairs table for persistence.
Uses PostgreSQL bit_count() for efficient Hamming distance calculation,
which is O(n) instead of O(n²) for in-memory comparisons.
Instance Attribute Summary
Attributes included from Workers::StatusBroadcastable
Instance Method Summary collapse
Methods included from Workers::StatusBroadcastable::Overrides
Instance Method Details
#perform(options = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/workers/image_duplicate_finder_worker.rb', line 25 def perform( = {}) = .with_indifferent_access threshold = ([:threshold] || 10).to_i incremental = [:incremental].to_s == 'true' redirect_to = [:redirect_to] store started_at: Time.current.iso8601 store threshold: threshold store incremental: incremental store redirect_to: redirect_to if redirect_to.present? store message: 'Scanning for duplicate images...' pairs_found = find_and_store_duplicates(threshold: threshold, incremental: incremental) store completed_at: Time.current.iso8601 store pairs_found: pairs_found store message: "Found #{pairs_found} duplicate pairs" store info_message: "Duplicate detection complete. Found #{pairs_found} pairs with threshold ≤ #{threshold}." Rails.logger.info "[ImageDuplicateFinderWorker] Found #{pairs_found} duplicate pairs with threshold #{threshold}" end |