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

#10882 Slow Media Tab View #11280

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ interface FileDao {
fun getFolderContent(parentId: Long): List<FileEntity>

@Query(
"SELECT * FROM filelist WHERE modified >= :startDate" +
" AND modified < :endDate" +
"SELECT * FROM filelist WHERE created >= :startDate" +
" AND created < :endDate" +
" AND (content_type LIKE 'image/%' OR content_type LIKE 'video/%')" +
" AND file_owner = :fileOwner" +
" ORDER BY ${ProviderTableMeta.FILE_DEFAULT_SORT_ORDER}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ data class FileEntity(
@ColumnInfo(name = ProviderTableMeta.FILE_PARENT)
val parent: Long?,
@ColumnInfo(name = ProviderTableMeta.FILE_CREATION)
val creation: Long?,
val created: Long?,
@ColumnInfo(name = ProviderTableMeta.FILE_MODIFIED)
val modified: Long?,
@ColumnInfo(name = ProviderTableMeta.FILE_CONTENT_TYPE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ private OCFile createFileInstance(FileEntity fileEntity) {
}
}
ocFile.setFileLength(nullToZero(fileEntity.getContentLength()));
ocFile.setCreationTimestamp(nullToZero(fileEntity.getCreation()));
ocFile.setCreationTimestamp(nullToZero(fileEntity.getCreated()));
ocFile.setModificationTimestamp(nullToZero(fileEntity.getModified()));
ocFile.setModificationTimestampAtLastSyncForData(nullToZero(fileEntity.getModifiedAtLastSyncForData()));
ocFile.setLastSyncDateForProperties(nullToZero(fileEntity.getLastSyncDate()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,6 @@ protected void onPostExecute(GallerySearchTask.Result result) {

photoFragment.setLoading(false);
photoFragment.searchCompleted(result.emptySearch, result.lastTimestamp);

if (result.success && photoFragment.getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) {
photoFragment.showAllGalleryItems();
} else {
photoFragment.setEmptyListMessage(SearchType.GALLERY_SEARCH);
}
}
}

Expand All @@ -146,52 +140,40 @@ private boolean parseMedia(long startDate, long endDate, List<Object> remoteFile
Map<String, OCFile> localFilesMap = RefreshFolderOperation.prefillLocalFilesMap(null,
storageManager.getGalleryItems(startDate * 1000L,
endDate * 1000L));
List<OCFile> filesToAdd = new ArrayList<>();
List<OCFile> filesToUpdate = new ArrayList<>();
long filesAdded = 0, filesUpdated = 0, filesDeleted = 0, unchangedFiles = 0;

OCFile localFile;
for (Object file : remoteFiles) {
OCFile ocFile = FileStorageUtils.fillOCFile((RemoteFile) file);

localFile = localFilesMap.remove(ocFile.getRemotePath());
OCFile localFile = localFilesMap.remove(ocFile.getRemotePath());

if (localFile == null) {
// add new file
filesToAdd.add(ocFile);
storageManager.saveFile(ocFile);
filesAdded++;
} else if (!localFile.getEtag().equals(ocFile.getEtag())) {
// update file
ocFile.setLastSyncDateForData(System.currentTimeMillis());
filesToUpdate.add(ocFile);
storageManager.saveFile(ocFile);
filesUpdated++;
} else {
unchangedFiles++;
}
}

// add new files
for (OCFile file : filesToAdd) {
storageManager.saveFile(file);
}

// update existing files
for (OCFile file : filesToUpdate) {
storageManager.saveFile(file);
}

// existing files to remove
filesDeleted = localFilesMap.values().size();

for (OCFile file : localFilesMap.values()) {
storageManager.removeFile(file, true, true);
}

Log_OC.d(this, "Gallery search result:" +
" new: " + filesToAdd.size() +
" updated: " + filesToUpdate.size() +
" deleted: " + localFilesMap.size());

return didNotFindNewResults(filesToAdd, filesToUpdate, localFilesMap.values());
}
" new: " + filesAdded +
" updated: " + filesUpdated +
" deleted: " + filesDeleted +
" unchanged: " + unchangedFiles);

private boolean didNotFindNewResults(List<OCFile> filesToAdd,
List<OCFile> filesToUpdate,
Collection<OCFile> filesToRemove) {
return filesToAdd.isEmpty() && filesToUpdate.isEmpty() && filesToRemove.isEmpty();
return (filesAdded + filesUpdated + filesDeleted + unchangedFiles > 0) ? false : true;
}

public static class Result {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,16 +232,17 @@ private void searchAndDisplay() {
@SuppressLint("NotifyDataSetChanged")
public void searchCompleted(boolean emptySearch, long lastTimeStamp) {
photoSearchQueryRunning = false;
mAdapter.notifyDataSetChanged();

if (mAdapter.isEmpty()) {
if (emptySearch && mAdapter.isEmpty()) {
setEmptyListMessage(SearchType.GALLERY_SEARCH);
return;
}

if (emptySearch && mAdapter.getItemCount() > 0) {
Log_OC.d(this, "End gallery search");
if(!emptySearch) {
mAdapter.notifyDataSetChanged();
this.showAllGalleryItems();
return;
}

if (daySpan == 30) {
daySpan = 90;
} else if (daySpan == 90) {
Expand Down