Apply various performance improvements

This commit is contained in:
codeking 2026-01-12 16:42:30 +01:00
parent 91d1a93ddf
commit b325a0d23c
2 changed files with 17 additions and 13 deletions

View file

@ -8,7 +8,6 @@ from core.services.WebServiceApiService import WebServiceApiService
from io import BytesIO from io import BytesIO
from typing import Optional from typing import Optional
import hashlib import hashlib
import requests
import shutil import shutil
import tarfile import tarfile
@ -61,6 +60,8 @@ class ApplicationVersionController:
@staticmethod @staticmethod
def __install(application_version: ApplicationVersion, application_version_observer: Optional[ApplicationVersionObserver] = None, proxies: Optional[dict] = None): def __install(application_version: ApplicationVersion, application_version_observer: Optional[ApplicationVersionObserver] = None, proxies: Optional[dict] = None):
import requests
if application_version_observer is not None: if application_version_observer is not None:
application_version_observer.notify('downloading', application_version) application_version_observer.notify('downloading', application_version)

View file

@ -11,7 +11,6 @@ from core.models.session.ApplicationVersion import ApplicationVersion
from core.models.session.ProxyConfiguration import ProxyConfiguration from core.models.session.ProxyConfiguration import ProxyConfiguration
from typing import Optional from typing import Optional
import re import re
import requests
class WebServiceApiService: class WebServiceApiService:
@ -22,7 +21,7 @@ class WebServiceApiService:
response = WebServiceApiService.__get('/platforms/linux-x86_64/applications', None, proxies) response = WebServiceApiService.__get('/platforms/linux-x86_64/applications', None, proxies)
applications = [] applications = []
if response.status_code == requests.codes.ok: if response.status_code == 200:
for application in response.json()['data']: for application in response.json()['data']:
applications.append(Application(application['code'], application['name'], application['id'])) applications.append(Application(application['code'], application['name'], application['id']))
@ -34,7 +33,7 @@ class WebServiceApiService:
response = WebServiceApiService.__get(f'/platforms/linux-x86_64/applications/{code}/application-versions', None, proxies) response = WebServiceApiService.__get(f'/platforms/linux-x86_64/applications/{code}/application-versions', None, proxies)
application_versions = [] application_versions = []
if response.status_code == requests.codes.ok: if response.status_code == 200:
for application_version in response.json()['data']: for application_version in response.json()['data']:
application_versions.append(ApplicationVersion(code, application_version['version_number'], application_version['format_revision'], application_version['id'], application_version['download_path'], application_version['released_at'], application_version['file_hash'])) application_versions.append(ApplicationVersion(code, application_version['version_number'], application_version['format_revision'], application_version['id'], application_version['download_path'], application_version['released_at'], application_version['file_hash']))
@ -46,7 +45,7 @@ class WebServiceApiService:
response = WebServiceApiService.__get('/platforms/linux-x86_64/appimage/client-versions', None, proxies) response = WebServiceApiService.__get('/platforms/linux-x86_64/appimage/client-versions', None, proxies)
client_versions = [] client_versions = []
if response.status_code == requests.codes.ok: if response.status_code == 200:
for client_version in response.json()['data']: for client_version in response.json()['data']:
client_versions.append(ClientVersion(client_version['version_number'], client_version['released_at'], client_version['id'], client_version['download_path'])) client_versions.append(ClientVersion(client_version['version_number'], client_version['released_at'], client_version['id'], client_version['download_path']))
@ -58,7 +57,7 @@ class WebServiceApiService:
response = WebServiceApiService.__get('/operators', None, proxies) response = WebServiceApiService.__get('/operators', None, proxies)
operators = [] operators = []
if response.status_code == requests.codes.ok: if response.status_code == 200:
for operator in response.json()['data']: for operator in response.json()['data']:
operators.append(Operator(operator['id'], operator['name'], operator['public_key'], operator['nostr_public_key'], operator['nostr_profile_reference'], operator['nostr_attestation']['event_reference'])) operators.append(Operator(operator['id'], operator['name'], operator['public_key'], operator['nostr_public_key'], operator['nostr_profile_reference'], operator['nostr_attestation']['event_reference']))
@ -70,7 +69,7 @@ class WebServiceApiService:
response = WebServiceApiService.__get('/locations', None, proxies) response = WebServiceApiService.__get('/locations', None, proxies)
locations = [] locations = []
if response.status_code == requests.codes.ok: if response.status_code == 200:
for location in response.json()['data']: for location in response.json()['data']:
locations.append(Location(location['country']['code'], location['code'], location['id'], location['country']['name'], location['name'], location['time_zone']['code'], location['operator_id'], location['provider']['name'], location['is_proxy_capable'], location['is_wireguard_capable'])) locations.append(Location(location['country']['code'], location['code'], location['id'], location['country']['name'], location['name'], location['time_zone']['code'], location['operator_id'], location['provider']['name'], location['is_proxy_capable'], location['is_wireguard_capable']))
@ -82,7 +81,7 @@ class WebServiceApiService:
response = WebServiceApiService.__get('/subscription-plans', None, proxies) response = WebServiceApiService.__get('/subscription-plans', None, proxies)
subscription_plans = [] subscription_plans = []
if response.status_code == requests.codes.ok: if response.status_code == 200:
for subscription_plan in response.json()['data']: for subscription_plan in response.json()['data']:
subscription_plans.append(SubscriptionPlan(subscription_plan['id'], subscription_plan['code'], subscription_plan['wireguard_session_limit'], subscription_plan['duration'], subscription_plan['price'], subscription_plan['features_proxy'], subscription_plan['features_wireguard'])) subscription_plans.append(SubscriptionPlan(subscription_plan['id'], subscription_plan['code'], subscription_plan['wireguard_session_limit'], subscription_plan['duration'], subscription_plan['price'], subscription_plan['features_proxy'], subscription_plan['features_wireguard']))
@ -96,7 +95,7 @@ class WebServiceApiService:
'location_id': location_id 'location_id': location_id
}, proxies) }, proxies)
if response.status_code == requests.codes.created: if response.status_code == 201:
return Subscription(response.headers['X-Billing-Code']) return Subscription(response.headers['X-Billing-Code'])
else: else:
@ -111,7 +110,7 @@ class WebServiceApiService:
response = WebServiceApiService.__get('/subscriptions/current', billing_code, proxies) response = WebServiceApiService.__get('/subscriptions/current', billing_code, proxies)
if response.status_code == requests.codes.ok: if response.status_code == 200:
subscription = response.json()['data'] subscription = response.json()['data']
return Subscription(billing_code, Subscription.from_iso_format(subscription['expires_at'])) return Subscription(billing_code, Subscription.from_iso_format(subscription['expires_at']))
@ -124,7 +123,7 @@ class WebServiceApiService:
response = WebServiceApiService.__get('/invoices/current', billing_code, proxies) response = WebServiceApiService.__get('/invoices/current', billing_code, proxies)
if response.status_code == requests.codes.ok: if response.status_code == 200:
response_data = response.json()['data'] response_data = response.json()['data']
@ -148,7 +147,7 @@ class WebServiceApiService:
response = WebServiceApiService.__get('/proxy-configurations/current', billing_code, proxies) response = WebServiceApiService.__get('/proxy-configurations/current', billing_code, proxies)
if response.status_code == requests.codes.ok: if response.status_code == 200:
proxy_configuration = response.json()['data'] proxy_configuration = response.json()['data']
return ProxyConfiguration(proxy_configuration['ip_address'], proxy_configuration['port'], proxy_configuration['username'], proxy_configuration['password'], proxy_configuration['location']['time_zone']['code']) return ProxyConfiguration(proxy_configuration['ip_address'], proxy_configuration['port'], proxy_configuration['username'], proxy_configuration['password'], proxy_configuration['location']['time_zone']['code'])
@ -163,7 +162,7 @@ class WebServiceApiService:
'public_key': public_key, 'public_key': public_key,
}, proxies) }, proxies)
if response.status_code == requests.codes.created: if response.status_code == 201:
return response.text return response.text
else: else:
return None return None
@ -171,6 +170,8 @@ class WebServiceApiService:
@staticmethod @staticmethod
def __get(path, billing_code: Optional[str] = None, proxies: Optional[dict] = None): def __get(path, billing_code: Optional[str] = None, proxies: Optional[dict] = None):
import requests
if billing_code is not None: if billing_code is not None:
headers = {'X-Billing-Code': billing_code} headers = {'X-Billing-Code': billing_code}
else: else:
@ -181,6 +182,8 @@ class WebServiceApiService:
@staticmethod @staticmethod
def __post(path, billing_code: Optional[str] = None, body: Optional[dict] = None, proxies: Optional[dict] = None): def __post(path, billing_code: Optional[str] = None, body: Optional[dict] = None, proxies: Optional[dict] = None):
import requests
if billing_code is not None: if billing_code is not None:
headers = {'X-Billing-Code': billing_code} headers = {'X-Billing-Code': billing_code}
else: else: