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 after split up #5337

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

tobiasKaminsky
Copy link
Member

This is second PR after splitup of #5150
It includes only code optimizations, done by @JorisBodin

Plan is to have all possible/needed tests in #5336 and then they need to work also on this PR before merging.

For checking that everything was split up correctly, you can compare this PR with #5150

Signed-off-by: tobiasKaminsky [email protected]

@@ -100,6 +100,114 @@ public FileDataStorageManager(Account account, ContentProviderClient contentProv
this.account = account;
}

private Cursor executeQuery(Uri uri, String[] projection, String selection,
Copy link
Member Author

Choose a reason for hiding this comment

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

We have the code style convention that if a line with parameters needs to be wrapped, that we then put all parameters in a separate line, so

private Cursor executeQuery(Uri uri, 
String[] projection, 
String selection,
String[] selectionArgs, 
String sortOrder, 
String errorMessage) 
{

I will change it, but just for your info :-) (it is not that bad, if we sometimes forget this, but it makes diff a bit easier, if a paremeter gets changed)

Copy link
Member

Choose a reason for hiding this comment

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

Hi,

I take note for next time :)

@tobiasKaminsky tobiasKaminsky force-pushed the fdsTests branch 3 times, most recently from c7998aa to 008f1af Compare June 10, 2020 11:15
@tobiasKaminsky tobiasKaminsky force-pushed the fdsTests branch 2 times, most recently from e9f1c79 to 37bf0dd Compare June 16, 2020 06:10
@tobiasKaminsky tobiasKaminsky changed the base branch from fdsTests to master June 16, 2020 06:47
@tobiasKaminsky tobiasKaminsky force-pushed the optimizationAfterSplit branch 2 times, most recently from 3c44331 to e05c649 Compare June 16, 2020 07:31
Copy link
Collaborator

Codacy Here is an overview of what got changed by this pull request:

Issues
======
+ Solved 5
- Added 18
           

Complexity decreasing per file
==============================
+ src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java  -3
         

See the complete overview on Codacy

return contentProviderResults;
}

private ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

} catch (RemoteException e) {
Log_OC.e(TAG, "Could not get file details: " + e.getMessage(), e);
cursor = null;
private ArrayList<OCFile> getFilesExistsID(ArrayList<OCFile> updatedFiles) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

return executeQuery(uri, null, selection, selectionArgs, null, errorMessage);
}

private ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations, String errorMessage) {
Copy link
Collaborator

Choose a reason for hiding this comment

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


listIDString.clear();
listPathString.clear();
StringBuilder inList = new StringBuilder(loopSize * 2);
Copy link
Collaborator

Choose a reason for hiding this comment

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

if (cursor != null) {
if (cursor.moveToFirst()) {
do {
OCFile ocFile = new OCFile(cursor.getString(cursor.getColumnIndex(ProviderTableMeta.FILE_PATH)));
Copy link
Collaborator

Choose a reason for hiding this comment

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

+ ProviderTableMeta.FILE_PATH
+ " IN (" + inList + "))";

ArrayList<String> selectionArgsList = new ArrayList<>();
Copy link
Collaborator

Choose a reason for hiding this comment

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

selectionArgsList.add(account.name);
selectionArgsList.addAll(listIDString);
selectionArgsList.addAll(listPathString);
String[] selectionArgs = selectionArgsList.toArray(new String[0]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Log_OC.e(TAG, "Failed querying for descendents in conflict " + e.getMessage(), e);
}
}
selectionArgs = new String[]{account.name, parentPath + "%"};
Copy link
Collaborator

Choose a reason for hiding this comment

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

for (int i = 0; i < loopSize; i++, processSize++) {
OCFile ocFile = updatedFiles.get(processSize);
if (i > 0) {
inList.append(",");
Copy link
Collaborator

Choose a reason for hiding this comment

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

processSize = 0;

do {
loopSize = Math.min((totalSize - processSize), 499);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Codacy Issue found: Useless parentheses.

return deleted;
}

private int deleteFiles(Uri uri, String where, String[] whereArgs) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

@@ -357,19 +451,24 @@ public void saveNewFile(OCFile newFile) {
* @param updatedFiles
* @param filesToRemove
*/
public void saveFolder(OCFile folder, List<OCFile> updatedFiles, Collection<OCFile> filesToRemove) {
public void saveFolder(OCFile folder, ArrayList<OCFile> updatedFiles, Collection<OCFile> filesToRemove) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

if (i > 0) {
inList.append(",");
}
inList.append("?");
Copy link
Collaborator

Choose a reason for hiding this comment

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

processSize = 0;

do {
loopSize = Math.min((totalSize - processSize), 998);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Codacy Issue found: Useless parentheses.

loopSize = Math.min((totalSize - processSize), 998);

listPathString.clear();
StringBuilder inList = new StringBuilder(folderContent.size() * 2);
Copy link
Collaborator

Choose a reason for hiding this comment

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

saveFile(newFile);
} else {
throw new IllegalArgumentException("Saving a new file in an unexisting folder");
private boolean isFileExists(ArrayList<OCFile> filesExists, OCFile ocFile) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

ArrayList<String> listIDString = new ArrayList<>();
ArrayList<String> listPathString = new ArrayList<>();

int totalSize, processSize, loopSize;
Copy link
Collaborator

Choose a reason for hiding this comment

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

@nextcloud-android-bot
Copy link
Collaborator

APK file: https://www.kaminsky.me/nc-dev/android-artifacts/14490.apk

qrcode

To test this change/fix you can simply download above APK file and install and test it in parallel to your existing Nextcloud app.

JorisBodin and others added 2 commits May 16, 2022 11:49
Optimization isFileExists
Fix sql injection
bulkInsert is more efficient
Split query for SQL variables limit and remove unused method
Remove bulkInsert and optimize applyBatch (only >= Android M)
Optimization RemoveSharesInFolder
Begin refactor FileDataStorageManager
Finish refactor FileDataStorageManager
Extract method for applyBatch and updateFiles
Extract insertFile and DeleteFiles
Finish extract deleteFiles and applyBatch
Prepare remove duplication
Add old comment
Remove createContentValueForFile doublon
Export createContentValue for saveFile()
Fix when search file
Fix bug on first connect
Oups

Signed-off-by: Joris Bodin <[email protected]>
Signed-off-by: tobiasKaminsky <[email protected]>
Signed-off-by: tobiasKaminsky <[email protected]>
@tobiasKaminsky tobiasKaminsky force-pushed the optimizationAfterSplit branch from e05c649 to a5196d5 Compare May 16, 2022 10:22
Signed-off-by: tobiasKaminsky <[email protected]>
@nextcloud-android-bot
Copy link
Collaborator

Codacy

Lint

TypemasterPR
Warnings8787
Errors04

SpotBugs

CategoryBaseNew
Bad practice3333
Correctness4544
Dodgy code360362
Experimental11
Internationalization99
Multithreaded correctness99
Performance6672
Security2929
Total552559

Lint increased!

SpotBugs increased!

@github-actions
Copy link

APK file: https://www.kaminsky.me/nc-dev/android-artifacts/5337.apk

qrcode

To test this change/fix you can simply download above APK file and install and test it in parallel to your existing Nextcloud app.

@nextcloud-android-bot
Copy link
Collaborator

@nextcloud-android-bot
Copy link
Collaborator

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