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

QMUIAssetsManager获取相簿时间过长 #1586

Open
fanyuecheng opened this issue Oct 18, 2024 · 0 comments
Open

QMUIAssetsManager获取相簿时间过长 #1586

fanyuecheng opened this issue Oct 18, 2024 · 0 comments

Comments

@fanyuecheng
Copy link

fanyuecheng commented Oct 18, 2024

Bug 表现
QMUIAssetsManager获取相簿时间过长

截图
Oct-18-2024 18-31-38

如何重现

  1. 相册中有上万图片
  2. 相册中有数十相簿,且每个相簿中均有相当数量的图片
  3. QMUIAlbumContentType 不为 QMUIAlbumContentTypeAll,为OnlyPhoto

预期的表现
打开相册不应该时间太久
研究发现是

  • (PHFetchResult<PHAsset *> *)fetchAssetsInAssetCollection:(PHAssetCollection *)assetCollection options:(nullable PHFetchOptions *)options;
    方法耗时较多,QMUI中,QMUIAssetsManager的enumerateAllAlbumsWithAlbumContentType:方法中遍历了PHAssetCollection对象并调用该方法用户获取相簿中图片数,后续初始化QMUIAssetsGroup又调用了一次用于模型内部phFetchResult属性,这调用的两次使得耗时增加了一倍

应该优化一下

  • (NSArray<PHAssetCollection *> *)fetchAllAlbumsWithAlbumContentType:(QMUIAlbumContentType)contentType showEmptyAlbum:(BOOL)showEmptyAlbum showSmartAlbum:(BOOL)showSmartAlbum;
    中如果PHFetchResult.count>0 即直接用于初始化 QMUIAssetsGroup
    最后返回 QMUIAssetsGroup 对象数组

其他信息

  • 设备: [例如模拟器、iPhone、iPad]
  • iOS 版本: [iOS 14.x]
  • Xcode 版本: [Xcode 12.x]
  • QMUI 版本: [4.x.x]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant