psn-php icon indicating copy to clipboard operation
psn-php copied to clipboard

Best practice to retrieve last trophies earned ?

Open spypix3l opened this issue 2 years ago • 4 comments

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 go through the user GameTitles, and for each title, I get the lastPlayedDateTime() to find the games played recently (after the last update in my Database).
  • I go through the whole list of trophies via Trophytitles(), TrophyGroups -> Trophies, and copy only those corresponding to the recent games played I found in my previous calls.

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 :-)

spypix3l avatar May 23 '22 09:05 spypix3l

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.

gabetavares avatar May 23 '22 19:05 gabetavares

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 :)

Tustin avatar May 23 '22 20:05 Tustin

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) :

  • I update the lastPlayedDateTime of all games for all users.
  • I only fetch trophies of games recently played.

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 !

spypix3l avatar May 24 '22 15:05 spypix3l

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.

stale[bot] avatar Jul 31 '22 17:07 stale[bot]