-
Notifications
You must be signed in to change notification settings - Fork 322
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
[Bug report] Android Platform query poor performance #1255
Comments
AI Summary: The user reports a bug in version 3.2.0 on Android where two SQL conditions appear to be duplicated in the query log. |
Please provide a complete minimal reproducible example. |
the sample code like thisimport 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:photo_manager/photo_manager.dart';
class PageTest extends StatefulWidget {
@override
State<PageTest> createState() => _PageTestState();
}
class _PageTestState extends State<PageTest> {
@override
void initState() {
super.initState();
PhotoManager.setLog(true);
backupTest();
}
@override
Widget build(BuildContext context) {
return Container(
color: Colors.blueAccent,
child: const Center(
child: Text('BackupTest'),
),
);
}
Future<List<AssetEntity>> backupTest() async {
final sw = Stopwatch()..start();
final List<AssetEntity> backupAssets = [];
final filterOptionGroup = FilterOptionGroup(
imageOption: const FilterOption(needTitle: true),
videoOption: const FilterOption(needTitle: true,),
);
final backupAlbums = await PhotoManager.getAssetPathList(
onlyAll: true, filterOption: filterOptionGroup);
for (final backupAlbum in backupAlbums) {
int page = 0;
final pageSize = 1000;
bool isEnd = false;
while (!isEnd) {
final queryStopWatch = Stopwatch()..start();
final assetList =
await backupAlbum.getAssetListPaged(page: page, size: pageSize);
queryStopWatch.stop();
print('query time ${queryStopWatch.elapsedMilliseconds}');
backupAssets.addAll(assetList);
page += 1;
if (assetList.length < pageSize) {
isEnd = true;
}
}
}
sw.stop();
print('total time ${sw.elapsedMilliseconds}');
return backupAssets;
}
}
1. the query is too complexthe log is
This has taken a lot of time, so I change the filter code to
the log:
the query time is from 481ms up to 406ms Can I remove 'date_added >= 0 AND date_added <= 1736835350' and ' duration >=0 AND duration <=86400000' 2. The cursor counti found the cursor count is always : 57661 57661 is all my photo count, I think this is a problem How do I set the limit to make the cursor count is my pageSize (1000) The relevant code is here, you dont' use the limit so the cursor count is always is all my photos
disable the log , the query time will up to "350ms"
3. check the file existChecking if the file exists is too expensive How do I set the "checkIfExists = false“ in toAssetEntity method. In my use case, I don't need to check if the file exists here. I can check it when I use the file later. change the sourc code set checkIfExists = false the query time will up to 150ms
|
Switch to |
Thanks, I will try。 And how do I disable the checkIfExists in here |
Version
3.2.0
Platforms
Android
Device Model
Android 15
flutter info
How to reproduce?
I use filterOption is :
Logs
Example code (optional)
No response
Contact
No response
The text was updated successfully, but these errors were encountered: