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

src: cache negative results in GetPackageJSON #56834

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions src/node_modules.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,18 @@ const BindingData::PackageConfig* BindingData::GetPackageJSON(
return &cache_entry->second;
}

if (binding_data->missing_package_configs_.contains(std::string(path))) {
return nullptr;
}

PackageConfig package_config{};
package_config.file_path = path;
// No need to exclude BOM since simdjson will skip it.
if (ReadFileSync(&package_config.raw_json, path.data()) < 0) {
// Cache the failed read so that other queries in the same folder don't
// keep probing the file system
binding_data->missing_package_configs_.insert(
std::string(path));
return nullptr;
}
// In some systems, std::string is annotated to generate an
Expand Down
1 change: 1 addition & 0 deletions src/node_modules.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class BindingData : public SnapshotableObject {

private:
std::unordered_map<std::string, PackageConfig> package_configs_;
std::unordered_set<std::string> missing_package_configs_;
simdjson::ondemand::parser json_parser;
// returns null on error
static const PackageConfig* GetPackageJSON(
Expand Down
Loading