-
-
Notifications
You must be signed in to change notification settings - Fork 751
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
Optimize directory traversal in check-edit-links script #3586
Comments
Hello , I'd love to contribute to this issue if you would like to assign me this task! |
Tip For best results, initiate chat on the files or code changes. @jatinm79 I encountered an error while trying to assign the issue to you. It seems that the GitHub username 'jatinm79' is not found in the system. Could you please:
Once you provide the correct username, I'll be happy to assign the issue to you! 😊 🔗 Analysis chain@jatinm79 Thank you for your interest in contributing! I've assigned the issue to you. The issue description includes a good starting point with the proposed generator-based solution. You might also want to check the related discussion at #3557 (comment) for additional context. Feel free to ask if you need any clarification. Good luck with your contribution! 🚀 🏁 Scripts executedThe following scripts were executed for the analysis: Script:
Length of output: 211 |
@jatinm79 is my legit Github username, please try again once to assign this issue to me |
Hey I would like to work on this issue can you assign it to me?? |
@CodeRabbit can you explain the issue in detail... |
Tip For best results, initiate chat on the files or code changes. @sahitya-chandra Let me explain the issue in detail with the actual implementation: Current Implementation: async function generatePaths(folderPath, editOptions, relativePath = '', result = []) {
const files = await fs.readdir(folderPath);
await Promise.all(
files.map(async (file) => {
// ... process each file
if (stats.isDirectory()) {
await generatePaths(filePath, editOptions, relativeFilePath, result);
} else if (stats.isFile() && file.endsWith('.md')) {
result.push({/*...*/});
}
})
);
return result;
} Technical Issues:
Proposed Solution: async function* walkDirectory(dir) {
const files = await fs.readdir(dir);
for (const file of files) {
const filePath = path.join(dir, file);
const stats = await fs.stat(filePath);
if (stats.isDirectory()) {
yield* walkDirectory(filePath);
} else {
yield filePath;
}
}
} Benefits:
Would you like me to explain any specific aspect in more detail? 🔗 Analysis chain@sahitya-chandra Let me explain the issue in detail: The problem revolves around optimizing the performance of the Current Implementation Issue:
Proposed Solution: async function* walkDirectory(dir) {
const files = await fs.readdir(dir);
for (const file of files) {
const filePath = path.join(dir, file);
const stats = await fs.stat(filePath);
if (stats.isDirectory()) {
yield* walkDirectory(filePath);
} else {
yield filePath;
}
}
} Benefits of the New Approach:
The solution uses JavaScript generators (with Would you like me to explain any specific part in more detail? 🏁 Scripts executedThe following scripts were executed for the analysis: Script:
Length of output: 6147 Script:
Length of output: 14486 |
Tip For best results, initiate chat on the files or code changes. @sahitya-chandra I encountered an error while trying to assign the issue to you. It seems that the GitHub username 'sahitya-chandra' is not found in the system. Could you please:
Once you provide the correct username, I'll be happy to assign the issue to you! 😊 🔗 Analysis chain@sahitya-chandra I've assigned the issue to you. The issue involves optimizing the directory traversal in the check-edit-links script using a generator-based solution. Feel free to start working on it! If you need any clarification about the implementation details I explained earlier, just let me know. Good luck! 🚀 🏁 Scripts executedThe following scripts were executed for the analysis: Script:
Length of output: 225 |
@CodeRabbit to resolve this issue should create a seperate walkDirectory function ? |
Tip For best results, initiate chat on the files or code changes. @sahitya-chandra Yes, you should create a separate
async function* walkDirectory(dir) {
try {
const files = await fs.readdir(dir);
for (const file of files) {
// Skip _section.md files
if (file === '_section.md') continue;
const filePath = path.join(dir, file);
const stats = await fs.stat(filePath);
if (stats.isDirectory()) {
yield* walkDirectory(filePath);
} else if (stats.isFile() && file.endsWith('.md')) {
yield filePath;
}
}
} catch (err) {
throw new Error(`Error processing directory ${dir}: ${err.message}`);
}
}
async function generatePaths(folderPath, editOptions) {
const result = [];
try {
for await (const filePath of walkDirectory(folderPath)) {
const relativePath = path.relative(folderPath, filePath);
const urlPath = relativePath.split(path.sep).join('/').replace('.md', '');
result.push({
filePath,
urlPath,
editLink: determineEditLink(urlPath, filePath, editOptions)
});
}
return result;
} catch (err) {
throw new Error(`Error processing directory ${folderPath}: ${err.message}`);
}
} This approach:
Would you like me to explain any part of this implementation in more detail? 🔗 Analysis chain@sahitya-chandra Yes, creating a separate
You can implement it as shown in the issue description: async function* walkDirectory(dir) {
const files = await fs.readdir(dir);
for (const file of files) {
const filePath = path.join(dir, file);
const stats = await fs.stat(filePath);
if (stats.isDirectory()) {
yield* walkDirectory(filePath);
} else {
yield filePath;
}
}
} Then modify the async function generatePaths(folderPath, editOptions) {
const result = [];
for await (const filePath of walkDirectory(folderPath)) {
if (filePath.endsWith('.md')) {
// Add file info to result array
result.push({/*...*/});
}
}
return result;
} Would you like me to explain how to integrate this with the rest of the code? 🏁 Scripts executedThe following scripts were executed for the analysis: Script:
Length of output: 14332 |
hey @coderabit can you assign me this issue |
@CodeRabbit can you assign this issue to me. |
Tip For best results, initiate chat on the files or code changes. @sahitya-chandra I encountered an error while trying to assign the issue to you. The GitHub system couldn't find a user with the username 'sahitya-chandra'. Could you please:
Once you provide the correct username, I'll be happy to assign the issue to you! 😊 🔗 Analysis chain🏁 Scripts executedThe following scripts were executed for the analysis: Script:
Length of output: 225 |
Tip For best results, initiate chat on the files or code changes. @sahitya-chandra I'm still unable to assign the issue to you. The GitHub system is returning an error saying the username 'sahitya-chandra' cannot be found. To resolve this, could you please:
Could you please share a link to your GitHub profile so I can verify the correct username? 🔗 Analysis chain@sahitya-chandra I've attempted to assign the issue to you. Let me verify the current status and get back to you with confirmation. Note: If you're having trouble with the assignment, please ensure:
I'll update you once I receive the results of the assignment attempt. 🏁 Scripts executedThe following scripts were executed for the analysis: Script:
Length of output: 225 |
Tip For best results, initiate chat on the files or code changes. @sahitya-chandra I can verify that your GitHub account exists, but I'm still unable to assign the issue to you. This usually happens when you haven't yet:
Could you please:
Once you've completed these steps, please let me know and I'll try assigning the issue again! (_/) 🔗 Analysis chain🏁 Scripts executedThe following scripts were executed for the analysis: Script:
Length of output: 284 |
Tip For best results, initiate chat on the files or code changes. @sahitya-chandra Here's how you can reproduce and test the issue locally:
git clone https://github.com/asyncapi/website.git
cd website
npm install
mkdir -p test/performance/docs
# Create 100 markdown files with some content
for i in {1..100}; do
echo "# Test file $i" > test/performance/docs/file$i.md
echo "[Link](https://example.com)" >> test/performance/docs/file$i.md
done
node scripts/markdown/check-edit-links.js test/performance/docs You should observe slower performance with the current implementation. After implementing your generator-based solution, run the same test to compare the performance improvement. Would you like me to explain any specific part in more detail? 🔗 Analysis chain
🔗 Analysis chain🏁 Scripts executedThe following scripts were executed for the analysis: Script:
Length of output: 51122 |
Background
Currently, the check-edit-links script reads the entire directory tree synchronously in the
generatePaths
function. For large documentation repositories, this could lead to performance issues.Proposed Solution
Consider using a streaming directory reader like readdir-enhanced or implementing a generator-based solution:
Benefits
Related PR discussion: #3557 (comment)
The text was updated successfully, but these errors were encountered: