Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent full indexing (index_all) from being called multiple times #2864

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
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: 10 additions & 0 deletions lib/ruby_indexer/lib/ruby_indexer/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Index

class UnresolvableAliasError < StandardError; end
class NonExistingNamespaceError < StandardError; end
class IndexNotEmptyError < StandardError; end

# The minimum Jaro-Winkler similarity score for an entry to be considered a match for a given fuzzy search query
ENTRY_SIMILARITY_THRESHOLD = 0.7
Expand Down Expand Up @@ -360,6 +361,15 @@ def resolve(name, nesting, seen_names = [])
).void
end
def index_all(indexable_paths: @configuration.indexables, &block)
# When troubleshooting an indexing issue, e.g. through irb, it's not obvious that `index_all` will augment the
# existing index values, meaning it may contain 'stale' entries. This check ensures that the user is aware of this
# behavior and can take appropriate action.
# binding.break
if @entries.any?
raise IndexNotEmptyError,
"The index is not empty. To prevent invalid entries, `index_all` can only be called once."
end

RBSIndexer.new(self).index_ruby_core
# Calculate how many paths are worth 1% of progress
progress_step = (indexable_paths.length / 100.0).ceil
Expand Down
7 changes: 7 additions & 0 deletions lib/ruby_indexer/test/index_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2023,5 +2023,12 @@ def test_build_non_redundant_name
),
)
end

def test_prevents_multiple_calls_to_index_all
# For this test class, `index_all` is already called once in `setup`.
assert_raises(Index::IndexNotEmptyError) do
@index.index_all
end
end
end
end
Loading