1
0
forked from Hay1tsme/artemis

Diva: Adding threading to score loading

This commit is contained in:
Midorica 2023-07-24 13:19:54 -04:00
parent 156b4e4ede
commit 5a4baba102

View File

@ -3,6 +3,7 @@ from typing import Any, List, Dict
import logging import logging
import json import json
import urllib import urllib
from threading import Thread
from core.config import CoreConfig from core.config import CoreConfig
from titles.diva.config import DivaConfig from titles.diva.config import DivaConfig
@ -663,11 +664,8 @@ class DivaBase:
return pv_result return pv_result
def handle_get_pv_pd_request(self, data: Dict) -> Dict: def task_generateScoreData(self, data: Dict, pd_by_pv_id, song):
song_id = data["pd_pv_id_lst"].split(",")
pv = ""
for song in song_id:
if int(song) > 0: if int(song) > 0:
# the request do not send a edition so just perform a query best score and ranking for each edition. # the request do not send a edition so just perform a query best score and ranking for each edition.
# 0=ORIGINAL, 1=EXTRA # 0=ORIGINAL, 1=EXTRA
@ -702,11 +700,30 @@ class DivaBase:
) )
self.logger.debug(f"pv_result = {pv_result}") self.logger.debug(f"pv_result = {pv_result}")
pd_by_pv_id.append(urllib.parse.quote(pv_result))
pv += urllib.parse.quote(pv_result)
else: else:
pv += urllib.parse.quote(f"{song}***") pd_by_pv_id.append(urllib.parse.quote(f"{song}***"))
pv += "," pd_by_pv_id.append(",")
def handle_get_pv_pd_request(self, data: Dict) -> Dict:
song_id = data["pd_pv_id_lst"].split(",")
pv = ""
threads = []
pd_by_pv_id = []
for song in song_id:
thread_ScoreData = Thread(target=self.task_generateScoreData(data, pd_by_pv_id, song))
threads.append(thread_ScoreData)
for x in threads:
x.start()
for x in threads:
x.join()
for x in pd_by_pv_id:
pv += x
response = "" response = ""
response += f"&pd_by_pv_id={pv[:-1]}" response += f"&pd_by_pv_id={pv[:-1]}"