尝试缓存下载队列状态,避免下载按钮直接访问数据库

This commit is contained in:
juntao
2021-09-29 17:44:40 +08:00
parent 047c45db9a
commit ad6114a44b
5 changed files with 20 additions and 9 deletions

View File

@ -527,13 +527,25 @@ public class DownloadManager implements DownloadStatusListener {
* @param url 下载链接
* @return null表示下载列表中不存在该任务否则返回下载任务
*/
// TODO 避免每次访问都从数据库里取数据
@Nullable
@WorkerThread
public DownloadEntity getDownloadEntityByUrl(String url) {
if (TextUtils.isEmpty(url)) return null;
return mDownloadDao.get(url);
}
/**
* 根据 url 获取下载任务 (仅保证下载状态一致)
*
* @param url 下载链接
* @return null表示下载列表中不存在该任务否则返回下载任务
*/
@Nullable
public DownloadEntity getDownloadEntitySnapshotByUrl(String url) {
if (TextUtils.isEmpty(url)) return null;
return mDownloadDao.getSnapshot(url);
}
/**
* 根据包名获取某一个下载任务 (涉及数据库查询,请优先在子线程调用)
*
@ -651,7 +663,6 @@ public class DownloadManager implements DownloadStatusListener {
private void putStatus(String url, DownloadStatus status) {
statusMap.put(url, status);
onTaskStatusChanged(getDownloadEntityByUrl(url));
}
public DownloadStatus getStatus(String url) {