speedup search

This commit is contained in:
tobiasKaminsky 2017-05-03 13:14:30 +02:00 committed by Mario Danic
parent 6c2d881dfe
commit 33ed0626ff
2 changed files with 97 additions and 60 deletions

View file

@ -1,21 +1,20 @@
/** /**
* ownCloud Android client application * ownCloud Android client application
* * <p>
* Copyright (C) 2012 Bartek Przybylski * Copyright (C) 2012 Bartek Przybylski
* Copyright (C) 2015 ownCloud Inc. * Copyright (C) 2015 ownCloud Inc.
* * <p>
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2, * it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation. * as published by the Free Software Foundation.
* * <p>
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* * <p>
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/ */
package com.owncloud.android.datamodel; package com.owncloud.android.datamodel;
@ -253,7 +252,7 @@ public class FileDataStorageManager {
public OCFile saveFileWithParent(OCFile file, Context context) { public OCFile saveFileWithParent(OCFile file, Context context) {
if (file.getParentId() != 0 || file.getRemotePath().equals("/")) { if (file.getParentId() != 0 || file.getRemotePath().equals("/")) {
saveFile(file); // nothing needed
} else { } else {
String remotePath = file.getRemotePath(); String remotePath = file.getRemotePath();
@ -1104,7 +1103,6 @@ public class FileDataStorageManager {
} }
/** /**
* Get first share bound to a file with a known path and given {@link ShareType}. * Get first share bound to a file with a known path and given {@link ShareType}.
* *
@ -1981,6 +1979,7 @@ public class FileDataStorageManager {
return c; return c;
} }
public OCCapability getCapability(String accountName) { public OCCapability getCapability(String accountName) {
OCCapability capability = null; OCCapability capability = null;
Cursor c = getCapabilityCursorForAccount(accountName); Cursor c = getCapabilityCursorForAccount(accountName);
@ -2065,6 +2064,19 @@ public class FileDataStorageManager {
} }
} }
public void saveVirtuals(VirtualFolderType type, List<ContentValues> values) {
if (getContentResolver() != null) {
getContentResolver().bulkInsert(ProviderTableMeta.CONTENT_URI_VIRTUAL, values.toArray(new ContentValues[values.size()]));
} else {
try {
getContentProviderClient().bulkInsert(ProviderTableMeta.CONTENT_URI_VIRTUAL, values.toArray(new ContentValues[values.size()]));
} catch (RemoteException e) {
Log_OC.e(TAG, FAILED_TO_INSERT_MSG + e.getMessage(), e);
}
}
}
public void saveVirtual(VirtualFolderType type, OCFile file) { public void saveVirtual(VirtualFolderType type, OCFile file) {
ContentValues cv = new ContentValues(); ContentValues cv = new ContentValues();
cv.put(ProviderTableMeta.VIRTUAL_TYPE, type.toString()); cv.put(ProviderTableMeta.VIRTUAL_TYPE, type.toString());

View file

@ -24,6 +24,7 @@ package com.owncloud.android.ui.adapter;
import android.accounts.Account; import android.accounts.Account;
import android.content.ContentValues;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Color; import android.graphics.Color;
@ -48,6 +49,7 @@ import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.datamodel.ThumbnailsCacheManager; import com.owncloud.android.datamodel.ThumbnailsCacheManager;
import com.owncloud.android.datamodel.VirtualFolderType; import com.owncloud.android.datamodel.VirtualFolderType;
import com.owncloud.android.db.PreferenceManager; import com.owncloud.android.db.PreferenceManager;
import com.owncloud.android.db.ProviderMeta;
import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder; import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
import com.owncloud.android.files.services.FileUploader.FileUploaderBinder; import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.operations.RemoteOperationResult;
@ -485,11 +487,15 @@ public class FileListListAdapter extends BaseAdapter {
public void setData(ArrayList<Object> objects, ExtendedListFragment.SearchType searchType) { public void setData(ArrayList<Object> objects, ExtendedListFragment.SearchType searchType) {
mFiles = new Vector<>(); mFiles = new Vector<>();
// early exit
if (objects.size() > 0) {
if (searchType.equals(ExtendedListFragment.SearchType.SHARED_FILTER)) { if (searchType.equals(ExtendedListFragment.SearchType.SHARED_FILTER)) {
parseShares(objects); parseShares(objects);
} else { } else {
parseVirtuals(objects, searchType); parseVirtuals(objects, searchType);
} }
}
if (!searchType.equals(ExtendedListFragment.SearchType.PHOTO_SEARCH) && if (!searchType.equals(ExtendedListFragment.SearchType.PHOTO_SEARCH) &&
!searchType.equals(ExtendedListFragment.SearchType.PHOTOS_SEARCH_FILTER) && !searchType.equals(ExtendedListFragment.SearchType.PHOTOS_SEARCH_FILTER) &&
@ -558,14 +564,33 @@ public class FileListListAdapter extends BaseAdapter {
mStorageManager.deleteVirtuals(type); mStorageManager.deleteVirtuals(type);
ArrayList<ContentValues> contentValues = new ArrayList<>();
for (int i = 0; i < objects.size(); i++) { for (int i = 0; i < objects.size(); i++) {
OCFile ocFile = FileStorageUtils.fillOCFile((RemoteFile) objects.get(i)); OCFile ocFile;
// try to find it in database
ocFile = mStorageManager.getFileByPath(((RemoteFile) objects.get(i)).getRemotePath());
if (ocFile == null) {
// new
ocFile = FileStorageUtils.fillOCFile((RemoteFile) objects.get(i));
searchForLocalFileInDefaultPath(ocFile); searchForLocalFileInDefaultPath(ocFile);
ocFile = mStorageManager.saveFileWithParent(ocFile, mContext); ocFile = mStorageManager.saveFileWithParent(ocFile, mContext);
mStorageManager.saveVirtual(type, ocFile);
} }
mFiles.addAll(mStorageManager.getVirtualFolderContent(type, onlyImages)); if (!onlyImages || MimeTypeUtil.isImage(ocFile)) {
mFiles.add(ocFile);
}
ContentValues cv = new ContentValues();
cv.put(ProviderMeta.ProviderTableMeta.VIRTUAL_TYPE, type.toString());
cv.put(ProviderMeta.ProviderTableMeta.VIRTUAL_OCFILE_ID, ocFile.getFileId());
contentValues.add(cv);
}
mStorageManager.saveVirtuals(type, contentValues);
} }
/** /**