Skip to content

Commit

Permalink
Improved Wago Addons version check speed (#343)
Browse files Browse the repository at this point in the history
  • Loading branch information
AcidWeb committed Jul 20, 2022
1 parent 9dc5108 commit c891fb4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
34 changes: 23 additions & 11 deletions CB/Core.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def __init__(self):
self.dirIndex = None
self.wowiCache = {}
self.wagoCache = {}
self.wagoIdCache = None
self.tukuiCache = None
self.checksumCache = {}

Expand Down Expand Up @@ -557,7 +558,7 @@ def parse_wagoapp_payload(self, url):
payload = payload.json()
return f'https://addons.wago.io/addons/{payload["slug"]}'

@retry()
# TODO Improve the check when Wago Addons API will be will be expanded
def bulk_check(self, addons):
ids_wowi = []
ids_wago = []
Expand All @@ -566,22 +567,33 @@ def bulk_check(self, addons):
ids_wowi.append(re.findall(r'\d+', addon['URL'])[0].strip())
elif addon['URL'].startswith('https://addons.wago.io/addons/') and \
addon['URL'] not in self.config['IgnoreClientVersion'].keys():
ids_wago.append(addon['URL'].replace('https://addons.wago.io/addons/', ''))
ids_wago.append({'slug': addon['URL'].replace('https://addons.wago.io/addons/', ''), 'id': ''})
if len(ids_wowi) > 0:
payload = requests.get(f'https://api.mmoui.com/v3/game/WOW/filedetails/{",".join(ids_wowi)}.json',
headers=HEADERS, timeout=5).json()
if 'ERROR' not in payload:
for addon in payload:
self.wowiCache[str(addon['UID'])] = addon
# TODO Add bulk support
# if len(ids_wago) > 0 and self.config['WAAAPIKey'] != '':
# payload = requests.post(f'https://addons.wago.io/api/external/addons/_recents?game_version='
# f'{self.clientType}', json={'addons': ids_wago}, headers=HEADERS,
# auth=APIAuth('Bearer', self.config['WAAAPIKey']), timeout=5)
# self.parse_wagoaddons_error(payload.status_code)
# payload = payload.json()
# for addon in payload['addons']:
# self.wagoCache[addon] = payload['addons'][addon]
if len(ids_wago) > 0 and self.config['WAAAPIKey'] != '':
if not self.wagoIdCache:
self.wagoIdCache = requests.get(f'https://addons.wago.io/api/data/slugs?game_version={self.clientType}',
headers=HEADERS, timeout=5)
self.parse_wagoaddons_error(self.wagoIdCache.status_code)
self.wagoIdCache = self.wagoIdCache.json()
for addon in ids_wago:
if addon['slug'] in self.wagoIdCache['addons']:
addon['id'] = self.wagoIdCache['addons'][addon['slug']]['id']
payload = requests.post(f'https://addons.wago.io/api/external/addons/_recents?game_version='
f'{self.clientType}',
json={'addons': [addon["id"] for addon in ids_wago if addon["id"] != ""]},
headers=HEADERS, auth=APIAuth('Bearer', self.config['WAAAPIKey']), timeout=5)
self.parse_wagoaddons_error(payload.status_code)
payload = payload.json()
for addonid in payload['addons']:
for addon in ids_wago:
if addon['id'] == addonid:
self.wagoCache[addon['slug']] = payload['addons'][addonid]
break

# TODO WotLK Cleanup
@retry(custom_error='Failed to parse Tukui API data')
Expand Down
8 changes: 2 additions & 6 deletions CB/WagoAddons.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ def __init__(self, url, checkcache, clienttype, allowdev, apikey):
project = url.replace('https://addons.wago.io/addons/', '')
self.apiKey = apikey
self.clientType = clienttype
# TODO Add bulk support
if project in checkcache:
self.payload = checkcache[project]
self.payload['display_name'] = self.payload['name']
Expand Down Expand Up @@ -83,13 +82,10 @@ def get_current_version(self):
raise RuntimeError(f'{self.name}.\nFailed to find release for your client version.')
release = self.payload['recent_release'][max(release, key=release.get)]

self.downloadUrl = release['download_link']
self.downloadUrl = release['download_link'] if 'download_link' in release else release['link']
self.uiVersion = release['patch'] if 'patch' in release else release[f'supported_{self.clientType}_patch']
self.changelogUrl = f'{self.payload["website_url"]}/versions'
self.currentVersion = release['label']
if 'patch' in release:
self.uiVersion = release['patch']
else:
self.uiVersion = release[f'supported_{self.clientType}_patch']

@retry()
def get_addon(self):
Expand Down

0 comments on commit c891fb4

Please sign in to comment.