Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG修复 #114

Merged
merged 3 commits into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion app/lol/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def wrapper(*args, **kwargs):
class LolClientConnector:
def __init__(self):
self.sess = None
self.slowlySess = None
self.port = None
self.token = None
self.url = None
Expand Down Expand Up @@ -323,7 +324,7 @@ def getSummonerGamesByPuuidSlowly(self, puuid, begIndex=0, endIndex=4):
SummonerGamesNotFound: If the summoner games are not found.
"""
params = {"begIndex": begIndex, "endIndex": endIndex}
res = self.__get(
res = self.__slowlyGet(
f"/lol-match-history/v1/products/lol/{puuid}/matches", params
).json()

Expand Down Expand Up @@ -560,6 +561,12 @@ def __get(self, path, params=None):
return self.sess.get(url, params=params, verify=False)

@needLcu()
def __slowlyGet(self, path, params=None):
url = self.url + path
if not self.slowlySess:
self.slowlySess = requests.session()
return self.slowlySess.get(url, params=params, verify=False)
@needLcu()
def __post(self, path, data=None):
url = self.url + path
headers = {"Content-type": "application/json"}
Expand Down
14 changes: 7 additions & 7 deletions app/view/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -1129,24 +1129,24 @@ def process_item(item, isAllys=False):

assignTeamId(summoners)

self.gameInfoInterface.enemySummonerInfoReady.emit(
{'summoners': summoners, 'queueId': queueId})

if not self.isChampSelected:
summoners = []
allySummoners = []
with ThreadPoolExecutor() as executor:
futures = [executor.submit(process_item, item, True)
for item in allys]

for future in as_completed(futures):
result = future.result()
if result is not None:
summoners.append(result)
allySummoners.append(result)

assignTeamId(summoners)
assignTeamId(allySummoners)

self.gameInfoInterface.allySummonersInfoReady.emit(
{'summoners': summoners})
{'summoners': allySummoners})

self.gameInfoInterface.enemySummonerInfoReady.emit(
{'summoners': summoners, 'queueId': queueId})

if callback:
callback()
Expand Down
16 changes: 12 additions & 4 deletions app/view/search_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from ..components.search_line_edit import SearchLineEdit
from ..components.summoner_name_button import SummonerName
from ..lol.connector import LolClientConnector, connector
from ..lol.exceptions import SummonerGamesNotFound
from ..lol.exceptions import SummonerGamesNotFound, SummonerNotFound
from ..lol.tools import processGameData, processGameDetailData


Expand Down Expand Up @@ -1074,22 +1074,25 @@ def __onSearchButtonClicked(self):
cfg.set(cfg.searchHistory, ",".join([t for t in history if t][:10]), True) # 过滤空值, 只存十个

if self.loadGamesThread and self.loadGamesThread.is_alive():
connector.slowlySess.close()
self.loadGamesThreadStop.set()

def _():
try:
summoner = connector.getSummonerByName(targetName)
puuid = summoner["puuid"]
self.currentSummonerName = targetName
while self.loadGamesThread and self.loadGamesThread.is_alive():
time.sleep(.3)
self.loadGamesThread = threading.Thread(
target=self.loadGames, args=(puuid,))
target=self.loadGames, args=(puuid,), daemon=True)
self.loadGamesThread.start()
except:
except SummonerNotFound:
puuid = "-1"

self.summonerPuuidGetted.emit(puuid)

threading.Thread(target=_).start()
threading.Thread(target=_, daemon=True).start()

def loadGames(self, puuid):
"""
Expand Down Expand Up @@ -1121,6 +1124,11 @@ def loadGames(self, puuid):
return

for game in games["games"]:
# 用户在查询过程中切换了查询目标
if self.gamesView.gamesTab.puuid != puuid:
print(f"{self.gamesView.gamesTab.puuid} != {puuid}")
return

if time.time() - game['gameCreation'] / 1000 > 60 * 60 * 24 * 365:
return

Expand Down