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

Is it possible to use a local data dragon ? #66

Closed
Lucasnl opened this issue Nov 17, 2019 · 15 comments
Closed

Is it possible to use a local data dragon ? #66

Lucasnl opened this issue Nov 17, 2019 · 15 comments
Assignees
Labels
question Just a simple question.

Comments

@Lucasnl
Copy link

Lucasnl commented Nov 17, 2019

I just downloaded the data dragon files , and i want to know if it's possible (and easy to implement) to use the local files instead of using the cdn.

Thank you

@dolejska-daniel dolejska-daniel added the question Just a simple question. label Nov 17, 2019
@dolejska-daniel dolejska-daniel self-assigned this Nov 17, 2019
@dolejska-daniel
Copy link
Owner

dolejska-daniel commented Nov 17, 2019

Hey, that is a pretty good question!

Without any library code change it is possible but in a restricted way - if you override DataDragonAPI::SET_ENDPOINT during library initialization to local URL:

DataDragonAPI::initByVersion('custom_version_string', [
    DataDragonAPI::SET_ENDPOINT => 'http://localhost/riot-api-files/',
]);

All the generated URLs will then contain this one as a base path instead of https://ddragon.leagueoflegends.com/cdn/, but you will still need to follow original directory structure by which it is accessible through official CDN URL.

Eg. for champion icons its:

"{$endpoint}{$version}/img/champion/{$champion_name}.png";

@Lucasnl
Copy link
Author

Lucasnl commented Nov 17, 2019

thanks for the reply ! I will try to implement this .

@Lucasnl
Copy link
Author

Lucasnl commented Nov 17, 2019

Just did it ! thanks again! , but one more question.
Even using the data dragon local files , I still have a long TTFB (time to first byte) around 12 seconds, in other words is taking 12 seconds to load the entire page , is this normal or am I missing something ?

@dolejska-daniel
Copy link
Owner

dolejska-daniel commented Nov 17, 2019

@Lucasnl, it pretty much depends on your setup - what server do you use, what does the page do - I can't judge without any additional information.

@Lucasnl
Copy link
Author

Lucasnl commented Nov 17, 2019

@dolejska-daniel Im using localhost / Xampp

@dolejska-daniel
Copy link
Owner

@dolejska-daniel Im using localhost / Xampp

That doesn't tell me anything about your code 😅. 12 seconds is very long, so either you are doing something wrong or you've got something configured wrong.

@Lucasnl
Copy link
Author

Lucasnl commented Nov 18, 2019

well Here's an example , i have a input to search players match history so ...
$player =$_POST['searchPlayer']

if ($player ) {
$getSummoner=$api->getSummonerByName($player);
$sumId = $getSummoner->accountId;
$getGames= $api->getMatchlistByAccount($sumId);
$games = $getGames->matches;
} // This is what i'm doing to get all the info I need for the match history

now im doing a foreach to get all the detailed infos about the game

foreach ($games as $game) {

$ranked = $game->queue;
$gameId= $game->gameId;
$infoGame = $api->getMatch($gameId);
$getAllPlayers=$infoGame ->participantIdentities;
$stats = $infoGame ->participants;

// and now I have another foreach inside this foreach to access all the info about the player id

foreach ($getAllPlayers as $player)
{

$participantMatchId= $player->participantId;

// and another foreach inside this foreach to get the stats and items about the game

foreach ($stats as $stat){

$WinorLose= $stat->stats->win;

$item0 = $stat->stats->item0
$item1 = $stat->stats->item1 ....
}
}

}

and that's it , I don't know if a foreach inside another foreach is a problem or
there's another way to do it , im kinda new on this.

@dolejska-daniel
Copy link
Owner

dolejska-daniel commented Nov 18, 2019

Ok, I can see why this could take a lot of time since you are querrying the API separately for each game from matchlist. You could probably use async requests to speed up the process but you'd have to change your code a bit.

@Lucasnl
Copy link
Author

Lucasnl commented Nov 18, 2019

Thanks for the reply! I will try !

@Lucasnl
Copy link
Author

Lucasnl commented Nov 19, 2019

Hey its me again ,I promise this is the last time I bother you 😅

I tried to follow your the example from the Async request , I'm doing the league api initializating with my riot key , but all im getting is a blank page , im not getting the output :

I am TheKronnY (level 69)

I m Professor (level 106)

TehExuilKujdž (level 154)

is there any other config I have to make ?

@dolejska-daniel
Copy link
Owner

@Lucasnl these summoner names are from EUNE region - that is important.

@dolejska-daniel
Copy link
Owner

dolejska-daniel commented Nov 19, 2019

Btw code utilizing asynchronous requests would look something like this for case you presented:

$player = $_POST['searchPlayer'];

if ($player)
{
	$getSummoner = $api->getSummonerByName($player);
	$sumId = $getSummoner->accountId;
	$getGames = $api->getMatchlistByAccount($sumId);
	$games = $getGames->matches;
}

$onSuccess = function( Objects\MatchDto $infoGame ) {
	$getAllPlayers = $infoGame->participantIdentities;
	$stats = $infoGame->participants;
	foreach ($getAllPlayers as $player)
	{
		$participantMatchId = $player->participantId;
		foreach ($stats as $stat)
		{
			$WinorLose = $stat->stats->win;

			$item0 = $stat->stats->item0;
			$item1 = $stat->stats->item1;
			// ...
		}
	}
};

$onFailure = function( $ex ) {
	echo "Error occured: {$ex->getMessage()}";
};

foreach ($games as $game)
{
	$ranked = $game->queue;
	$gameId = $game->gameId;

	$api->nextAsync($onSuccess, $onFailure);
	$infoGame = $api->getMatch($gameId);
}

$api->commitAsync();

@Lucasnl
Copy link
Author

Lucasnl commented Nov 19, 2019

thanks for the help !

@dolejska-daniel
Copy link
Owner

@Lucasnl there has been a mistake in my code - last line is supposed to be $api->commitAsync(); not $api->commitAsync("accounts");. Make sure you fix it too 😅

@dolejska-daniel
Copy link
Owner

I'm assuming this has been solved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Just a simple question.
Projects
None yet
Development

No branches or pull requests

2 participants