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

fix: moved db operations to background thread/executor and fixed leaking objects #237

Merged
merged 9 commits into from
Jul 20, 2023

Conversation

desusai7
Copy link
Contributor

@desusai7 desusai7 commented Jun 20, 2023

Fixes

  • Moved db operations related to migration to an executor which executes them on a background thread
  • Closed leaking cursor object returned on checking if a status column exists
  • Closed the input and output streams opened when reading the response of HTTP Connection
  • Used try with resources wherever possible to close the auto-closeable
  • Reduced the length of code in synchronized blocks for better performance
  • Stopped bubbling up of exceptions in RudderNetworkManager

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • Version upgraded (project, README, gradle, etc)
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added unit tests for the code
  • I have made corresponding changes to the documentation

}
};
Future future = executor.submit(runnable);
// Need to perform db operations on a separate thread to support strict mode.
Future<?> future = Executors.newSingleThreadExecutor().submit(runnable);
try {
// todo: shall we add some timeout here ?
future.get();
Copy link
Contributor

Choose a reason for hiding this comment

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

since we are not utilising the Future reponse, we might use "executor.execute()"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, we are not using the future's response but we do need to await until the runnable finishes its execution, hence i went with using submit and getting future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

using executor.execute() now

@@ -466,11 +455,12 @@ private void deleteStatusColumn(SQLiteDatabase database) {

private boolean checkIfStatusColumnExists(SQLiteDatabase database) {
String checkIfStatusExistsSqlString = "PRAGMA table_info(events)";
Cursor allRows = null;
try {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can do try with resources for closeables. That's recommended approach

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, we can do that, will change it accordingly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

addressed it

@desusai7 desusai7 requested a review from itsdebs June 21, 2023 07:47
Desu Sai Venkat and others added 2 commits June 26, 2023 11:45
…ized blocks, catching exceptions at place of generation, using try with resources for auto-closeables
itsdebs
itsdebs previously approved these changes Jun 28, 2023
@desusai7 desusai7 requested a review from itsdebs July 20, 2023 07:11
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@1abhishekpandey 1abhishekpandey merged commit 9b66f65 into develop Jul 20, 2023
@1abhishekpandey 1abhishekpandey deleted the fix/strict_mode branch July 20, 2023 09:57
@1abhishekpandey 1abhishekpandey restored the fix/strict_mode branch July 20, 2023 10:45
@1abhishekpandey 1abhishekpandey deleted the fix/strict_mode branch December 4, 2023 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants