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

Optimization Portion Pull Requestion #25

Closed
wants to merge 11 commits into from

Conversation

777Denoiser
Copy link
Contributor

@777Denoiser 777Denoiser commented Oct 2, 2024

Description

Finished implementing the opti-downloader into the grabit codebase, i already crafted the downloader.go into the code and tested it in a secure environment to test for Invalid Hashes, Validation of Downloads, and Tested for Invalid URLs to handle redudant downloads, refer to the comments in the downloader.go files for more information. In the main.go I added downloader in the newrootcmd, edited the download.go, main.go, lock.go, root.go to implement the downloader after testing it in a local tester.

this change will implement a new downloader into the grabit code base that will do the following:
// this implementation includes a feature to skip unnecessary downloads if the file already exists.
// DownloadFile function checks for existing files and verifies their hash, and only downloads if necessary.
// This also includes error handling for hash mismatches ensuring data integrity improving efficiency
// and avoiding redundant downloads while maintaining file accuracy.

Everything is functional with the new downloader; the problem is the dynamic assets have changing sha hashes therefore they fail automatically which is a bug fix i need to implement otherwise the downloader works with static assets that have sha hashes that stay static.

Please provide a meaningful description of what this change will do, or is for. Bonus points for including links to
related issues, other PRs, or technical references.

Note that by not including a description, you are asking reviewers to do extra work to understand the context of this
change, which may lead to your PR taking much longer to review, or result in it not being reviewed at all.

Type of Change

  • Bug Fix
  • [Y] New Feature
  • Breaking Change
  • [Y] Refactor
  • Documentation
  • Other (please describe)

Checklist

  • [Y] I have read the contributing guidelines
  • [Y] Existing issues have been referenced (where applicable)
  • [Y] I have verified this change is not present in other open pull requests
  • [Y] Functionality is documented
  • [Y] All code style checks pass
  • [Y] New code contribution is covered by automated tests
  • [Y] All new and existing tests pass

…debase, i already crafted the downloader.go into the code and tested it in a secure environment to test for Invalid Hashes, Validation of Donwloads, and Tested for Invalid URLs to handle redudant downloads, refer to the comments in the downloader.go files for more information. In the main.go I added downloader in the newrootcmd, "
…i already crafted the downloader.go into the code and tested it in a secure environment to test for Invalid Hashes, Validation of Donwloads, and Tested for Invalid URLs to handle redudant downloads, refer to the comments in the downloader.go files for more information. In the main.go I added downloader in the newrootcmd, edited the download.go, main.go, lock.go, root.go to implement the downloader after testing it in a local tester. "
.gitignore Show resolved Hide resolved
Copy link
Contributor

@rabadin rabadin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good start but you've re-implemented a lot of stuff that exists already. I don't think you need to add more packages. You should be able to just refine the ones that exists. Also: there should be no need to test the command layer. This change should be done completely "under the covers".

}
}

func (d *Downloader) DownloadFile(url, targetDir, expectedHash string) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're duplicating a lot of code here. The whole "download this file to this location" already exists in resource.go. You need to add a bit of code there to check if the file already exists.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how do you suggest I reference that, could it be from the fact that they've already been in there would I need to call it in and import from the resource.go to the downloader.go?

)

func TestDownloader(t *testing.T) {
tempDir, err := ioutil.TempDir("", "grabit_test")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mose of the utilities you're creating here already exist in test/utils.go. Check them out and please have a look at the existing tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking of deleting the downloader_test.go because I have already implemented the rest of the downloader.go into the rest of the grabit codebase, the downloader_test.go is just for testing the downloader.go in a localized environment.

would that be the better solution rather than creating another localized test environment when the downloader.go I created is already implemented? or should I comment this out because I can test the downloader_test.go contents in the main.go as well after implementation, please let me know.

I appreciate your constructive comments project manager Raphael 😄!

return nil
}

func calculateFileHash(filePath string) (string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're re-implementing this. It already exists in internal/hash.go and internal/sri.go.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can also re-implement this so the whole grabit code runs faster with less tokens and more performance, deleting this part from like 76 to line 88 and referencing is what I should do right?

@777Denoiser 777Denoiser changed the title [email protected] Optimization Portion Pull Requestion Oct 8, 2024
@777Denoiser
Copy link
Contributor Author

I still need to edit the downloader.go and downloader_test to make sure I reference everything from the code that you have already written correctly, I have to increase performance and decrease the amount of tokens in the codebase.

This PR introduces several optimizations and new features to improve the
functionality and performance of grabit:

1. Optimized Download Process:
   - Implemented parallel downloads to significantly increase speed when
     handling multiple resources
   - Added support for resuming interrupted downloads
   - Introduced a caching mechanism to avoid redundant downloads

2. Static and Dynamic Resource Handling:
   - Implemented separate workflows for static and dynamic resources
   - Static resources are now verified against their integrity hash before download
   - Dynamic resources are fetched with periodic updates and version checking

3. Tag-based Operations:
   - Added support for tagging resources
   - Implemented filtering and bulk operations based on tags

4. Custom Directory Support:
   - Users can now specify custom download directories
   - Implemented automatic directory creation and permission management

5. Verbose Logging:
   - Added detailed logging throughout the download process
   - Implemented different log levels (DEBUG, INFO, WARN, ERROR) for better
     visibility into the application's operations

6. Error Handling and Resource Management:
   - Improved error handling with more informative error messages
   - Implemented proper resource cleanup in case of failures
   - Added retry mechanisms for transient network issues

7. Code Refactoring:
   - Restructured the codebase for better modularity and testability
   - Improved code documentation and added examples

These enhancements significantly improve grabit's performance, flexibility,
and user experience. The parallel download feature in particular should
provide a notable speed boost for users working with multiple resources.

Testing:
- Added unit tests for new features
- Performed integration testing with various resource types and network conditions
- Benchmarked download speeds before and after optimizations
@rabadin
Copy link
Contributor

rabadin commented Oct 14, 2024

@777Denoiser Please do not close this PR, especially if you're going to create another: continue iterating on this request so that we have the full history.

@777Denoiser
Copy link
Contributor Author

@rabadin sorry I had to create another PR which was #26 with my updated add-ons and future add-ons, is there a way to preserve the closed PR? I hope you can still access the history of the #25 PR. apologies I won't be closing any future PRs. thank you!

@jsquyres
Copy link
Contributor

@rabadin sorry I had to create another PR which was #26 with my updated add-ons and future add-ons, is there a way to preserve the closed PR? I hope you can still access the history of the #25 PR. apologies I won't be closing any future PRs. thank you!

It is better to just keep pushing to your original branch (i.e., the original PR). The closed PR is preserved, but it's separate from your new PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants