- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 18
Refactor to reuse dig command and improve maintainability #37
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot wasn't able to review any files in this pull request.
Files not reviewed (1)
- chkdm: Language not supported
| 📝 WalkthroughWalkthroughThe pull request introduces a new array variable  Changes
 Possibly related PRs
 Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit: 
 Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
 Other keywords and placeholders
 CodeRabbit Configuration File ( | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
chkdm (1)
58-59: LGTM! Good refactoring to centralize the dig command.The introduction of
dig_commandarray improves maintainability by centralizing the command configuration.Consider adding a comment explaining the purpose and expected format of the array:
+# Array containing dig command and its default options dig_command=(dig +short)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
- chkdm(3 hunks)
🔇 Additional comments (2)
chkdm (2)
104-104: LGTM! Proper array usage.The array expansion is correctly implemented using
"${dig_command[@]}".
111-111: LGTM! Consistent implementation in the query function.The array expansion is correctly implemented and maintains the existing error handling capabilities.
|  | ||
| function warnUpDNS() { | ||
| echo "${nofilterDNS[*]} ${secureDNS[*]} ${adblockDNS[*]}" | sed 's/ /\n/g' | xargs -I{} -P5 dig +short "$domain" @{} > /dev/null 2>&1 & | ||
| echo "${nofilterDNS[*]} ${secureDNS[*]} ${adblockDNS[*]}" | sed 's/ /\n/g' | xargs -I{} -P5 "${dig_command[@]}" "$domain" @{} > /dev/null 2>&1 & | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Improve array handling in parallel execution.
While the array expansion is correct, the current implementation might have issues if the dig command contains spaces or special characters when used with xargs.
Consider restructuring the command to handle the array expansion more safely:
-    echo "${nofilterDNS[*]} ${secureDNS[*]} ${adblockDNS[*]}" | sed 's/ /\n/g' | xargs -I{} -P5 "${dig_command[@]}" "$domain" @{} > /dev/null 2>&1 &
+    echo "${nofilterDNS[*]} ${secureDNS[*]} ${adblockDNS[*]}" | sed 's/ /\n/g' | while read -r dns; do
+        "${dig_command[@]}" "$domain" "@$dns" > /dev/null 2>&1 &
+        # Limit concurrent processes
+        while [ "$(jobs -r | wc -l)" -ge 5 ]; do
+            sleep 0.1
+        done
+    doneThis approach:
- Safely handles array expansion
- Maintains parallel execution limit
- Properly handles DNS servers with special characters
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| echo "${nofilterDNS[*]} ${secureDNS[*]} ${adblockDNS[*]}" | sed 's/ /\n/g' | xargs -I{} -P5 "${dig_command[@]}" "$domain" @{} > /dev/null 2>&1 & | |
| echo "${nofilterDNS[*]} ${secureDNS[*]} ${adblockDNS[*]}" | sed 's/ /\n/g' | while read -r dns; do | |
| "${dig_command[@]}" "$domain" "@$dns" > /dev/null 2>&1 & | |
| # Limit concurrent processes | |
| while [ "$(jobs -r | wc -l)" -ge 5 ]; do | |
| sleep 0.1 | |
| done | |
| done | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there will be special characters, and currently, it does contain a space, but it also works as expected. Is there something wrong?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PeterDaveHello You're right. I apologize for the overly cautious suggestion. The current implementation is working correctly because:
- The array expansion "${dig_command[@]}"properly handles the space indig +short
- The xargs usage with -I{}safely handles the DNS server parameter
- The parallel execution with -P5works as intended
The suggested change would add unnecessary complexity without providing tangible benefits. Let's keep the current implementation.
✏️ Learnings added
Learnt from: PeterDaveHello
PR: PeterDaveHello/chkdomain#37
File: chkdm:191-191
Timestamp: 2025-01-14T16:38:18.403Z
Learning: The parallel DNS query implementation in chkdomain using `xargs -I{} -P5` with array expansion `"${dig_command[@]}"` works correctly for handling spaces in the dig command and DNS server parameters. The suggestion to use a while loop with jobs control would add unnecessary complexity.
Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.
| /review | 
| PR Reviewer Guide 🔍Here are some key observations to aid the review process: 
 | 
| @CodiumAI-Agent /review | 
| Persistent review updated to latest commit 6892bdc | 
💪
Summary by CodeRabbit
digcommand variable.