Class: Fontist::Indexes::IncrementalIndexUpdater
- Inherits:
-
Object
- Object
- Fontist::Indexes::IncrementalIndexUpdater
- Defined in:
- lib/fontist/indexes/incremental_index_updater.rb
Overview
Service for performing incremental index updates Only scans changed files/directories instead of full scans
Constant Summary collapse
- SNAPSHOT_TTL =
5 minutes
300- CHANGE_DETECTION_TTL =
1 minute
60
Instance Attribute Summary collapse
-
#changes ⇒ Object
readonly
Returns the value of attribute changes.
-
#directory_path ⇒ Object
readonly
Returns the value of attribute directory_path.
Instance Method Summary collapse
-
#added_files ⇒ Object
Get list of added files.
-
#changes? ⇒ Boolean
Check if any changes were detected.
-
#initialize(directory_path) ⇒ IncrementalIndexUpdater
constructor
Initialize updater for a directory.
-
#modified_files ⇒ Object
Get list of modified files.
-
#removed_files ⇒ Object
Get list of removed files.
-
#stats ⇒ Object
Get scan statistics.
-
#update ⇒ Object
Perform incremental update Returns: Array of DirectoryChange objects.
Constructor Details
#initialize(directory_path) ⇒ IncrementalIndexUpdater
Initialize updater for a directory
12 13 14 15 |
# File 'lib/fontist/indexes/incremental_index_updater.rb', line 12 def initialize(directory_path) @directory_path = directory_path @changes = [] end |
Instance Attribute Details
#changes ⇒ Object (readonly)
Returns the value of attribute changes.
9 10 11 |
# File 'lib/fontist/indexes/incremental_index_updater.rb', line 9 def changes @changes end |
#directory_path ⇒ Object (readonly)
Returns the value of attribute directory_path.
9 10 11 |
# File 'lib/fontist/indexes/incremental_index_updater.rb', line 9 def directory_path @directory_path end |
Instance Method Details
#added_files ⇒ Object
Get list of added files
40 41 42 |
# File 'lib/fontist/indexes/incremental_index_updater.rb', line 40 def added_files @changes.select(&:added?) end |
#changes? ⇒ Boolean
Check if any changes were detected
55 56 57 |
# File 'lib/fontist/indexes/incremental_index_updater.rb', line 55 def changes? @changes.any? end |
#modified_files ⇒ Object
Get list of modified files
45 46 47 |
# File 'lib/fontist/indexes/incremental_index_updater.rb', line 45 def modified_files @changes.select(&:modified?) end |
#removed_files ⇒ Object
Get list of removed files
50 51 52 |
# File 'lib/fontist/indexes/incremental_index_updater.rb', line 50 def removed_files @changes.select(&:removed?) end |
#stats ⇒ Object
Get scan statistics
60 61 62 63 64 65 66 67 |
# File 'lib/fontist/indexes/incremental_index_updater.rb', line 60 def stats { total_changes: @changes.size, added: added_files.size, modified: modified_files.size, removed: removed_files.size, } end |
#update ⇒ Object
Perform incremental update Returns: Array of DirectoryChange objects
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/fontist/indexes/incremental_index_updater.rb', line 19 def update old_snapshot = load_snapshot new_snapshot = create_snapshot @changes = if old_snapshot.nil? # First scan - all files are new new_snapshot.files.map do |file| DirectoryChange.added(file[:filename], file) end else # Detect changes DirectoryChange.diff(old_snapshot, new_snapshot) end # Save new snapshot for next time save_snapshot(new_snapshot) @changes end |