mirror of
https://github.com/lilydjwg/nvchecker.git
synced 2025-03-10 06:14:02 +00:00
Use asyncio locks to ensure cache are always used
This commit is contained in:
parent
5df11f7b1a
commit
8a17ccfd6b
1 changed files with 14 additions and 8 deletions
|
@ -1,6 +1,7 @@
|
|||
# MIT licensed
|
||||
# Copyright (c) 2017 Yen Chi Hsuan <yan12125 at gmail dot com>
|
||||
|
||||
from asyncio.locks import Lock
|
||||
import os
|
||||
import re
|
||||
from xml.etree import ElementTree
|
||||
|
@ -13,20 +14,25 @@ _ANDROID_REPO_MANIFESTS = {
|
|||
}
|
||||
|
||||
_repo_manifests_cache = {}
|
||||
_repo_manifests_locks = {}
|
||||
|
||||
for repo in _ANDROID_REPO_MANIFESTS.keys():
|
||||
_repo_manifests_locks[repo] = Lock()
|
||||
|
||||
async def _get_repo_manifest(repo):
|
||||
if repo in _repo_manifests_cache:
|
||||
return _repo_manifests_cache[repo]
|
||||
with (await _repo_manifests_locks[repo]):
|
||||
if repo in _repo_manifests_cache:
|
||||
return _repo_manifests_cache[repo]
|
||||
|
||||
repo_xml_url = _ANDROID_REPO_MANIFESTS[repo]
|
||||
repo_xml_url = _ANDROID_REPO_MANIFESTS[repo]
|
||||
|
||||
async with session.get(repo_xml_url) as res:
|
||||
data = (await res.read()).decode('utf-8')
|
||||
async with session.get(repo_xml_url) as res:
|
||||
data = (await res.read()).decode('utf-8')
|
||||
|
||||
repo_manifest = ElementTree.fromstring(data)
|
||||
_repo_manifests_cache[repo] = repo_manifest
|
||||
repo_manifest = ElementTree.fromstring(data)
|
||||
_repo_manifests_cache[repo] = repo_manifest
|
||||
|
||||
return repo_manifest
|
||||
return repo_manifest
|
||||
|
||||
async def get_version(name, conf):
|
||||
repo = conf['repo']
|
||||
|
|
Loading…
Add table
Reference in a new issue