Tustin / psn-php

A PHP wrapper for the PSN API
https://tustin.dev/psn-php/
MIT License
358 stars 74 forks source link

Best practice to retrieve last trophies earned ? #211

Closed spypix3l closed 2 years ago

spypix3l commented 2 years ago

Hello,

This isn't really an issue, so I don't know if it's OK for me to ask my question here. Please let me know if I should post this somewhere else.

In my development, I try to make a copy of trophies earned in my Database, for a few users. This process can be quite long depending on the number of users, and the number of games owned by a user. This is why i'd like to know you'd have any advise for what I'm doing in order to optimize my code.

Currently, what I do is :

I wish there was a way that is more straight forward. For example, if we could get the Trophytitles in the order of most recently played games. But it doesn't look to be the case.

Any advise is welcome :-)

gabetavares commented 2 years ago

Hey @spypix3l,

Well straight to the answer, the better way is the way that suit your needs, since you provide no details of implementation and just few of your needs it gets difficulty to help at any point.

Correct me if I'm wrong, but you are trying to make a trophy tracker like clone, consider some stuff before:

  1. The user is new, or he already has some data on your platform?
  2. If the user is new you must get all the information you need and store it, if it is an old user set some logic to stop at some point, looping through the whole information over and over is a waste.
  3. You will store game data as well, or it will be just the trophy info? If not, how will you relate a trophy to it's game?
  4. The data you need are fetched from the user or from the game?

From those premises and questions you can start building some logic to write your code, but keep in mind and consider the limitations of each endpoint and the response data from them, trophies information for a game are fetched from an endpoint and the respective trophy information from some user is from another.

For your question about asking for implementation details on issues tab, I don't think it's allowed.

Tustin commented 2 years ago

Hi there, I might be able to implement some additional filtering for trophies based on time. I'd have to take a look at what properties are supplied for the trophy title / groups / trophy responses; but I imagine it should be a trivial change :)

spypix3l commented 2 years ago

Hi @gabetavares @Tustin Thank you for your answers.

Gabetavares, your correct with your assumptions. And this is what I'm doing. Of course, I need to initialise my database with games and trophy data for all the games owned and history of each new user. In my DB, games and game trophies are shared for all users, saving me from doing all the calls again when I already know the same npcommunicationId. This process is quite long, and I think there's nothing I could do to reduce this processing time.

When it's done, I try to avoid doing useless calls by only browsing the Trophytitles of games recently played. I kept working on it yesterday and fund this working quite well... for the moment (with just a few testing users) :

It's not too bad, but ability to browse trophies by earn date definitely sounds like a huge improvement :). I guess the same kind of filtering to get the most recently played games would be nice to have too.

Many thanks @Tustin - All I'm currently trying to achieve would be so difficult without you and all contributors to this project !

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.