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
16 17 18 19 |
# File 'lib/fontist/indexes/incremental_index_updater.rb', line 16 def initialize(directory_path) @directory_path = directory_path @changes = [] end |
Instance Attribute Details
#changes ⇒ Object (readonly)
Returns the value of attribute changes.
13 14 15 |
# File 'lib/fontist/indexes/incremental_index_updater.rb', line 13 def changes @changes end |
#directory_path ⇒ Object (readonly)
Returns the value of attribute directory_path.
13 14 15 |
# File 'lib/fontist/indexes/incremental_index_updater.rb', line 13 def directory_path @directory_path end |
Instance Method Details
#added_files ⇒ Object
Get list of added files
44 45 46 |
# File 'lib/fontist/indexes/incremental_index_updater.rb', line 44 def added_files @changes.select(&:added?) end |
#changes? ⇒ Boolean
Check if any changes were detected
59 60 61 |
# File 'lib/fontist/indexes/incremental_index_updater.rb', line 59 def changes? @changes.any? end |
#modified_files ⇒ Object
Get list of modified files
49 50 51 |
# File 'lib/fontist/indexes/incremental_index_updater.rb', line 49 def modified_files @changes.select(&:modified?) end |
#removed_files ⇒ Object
Get list of removed files
54 55 56 |
# File 'lib/fontist/indexes/incremental_index_updater.rb', line 54 def removed_files @changes.select(&:removed?) end |
#stats ⇒ Object
Get scan statistics
64 65 66 67 68 69 70 71 |
# File 'lib/fontist/indexes/incremental_index_updater.rb', line 64 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
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/fontist/indexes/incremental_index_updater.rb', line 23 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 |