Skip to content

Commit

Permalink
Separate polling intervals for liked and featured
Browse files Browse the repository at this point in the history
  • Loading branch information
andybak committed Dec 1, 2024
1 parent e660d65 commit a18182d
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions Assets/Scripts/zandria/ZandriaCreationsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,9 @@ public enum LoadStatus { NONE, LOADING_THUMBNAIL, LOADING_MODEL, FAILED, SUCCESS

// We implement polling for the "Featured" and "Liked" sections in order to show any
// new models that get featured or liked by the user while Blocks is running.
private const float POLLING_INTERVAL_SECONDS = 8;
private const float LIKED_POLLING_INTERVAL_SECONDS = 8;
// Less likely to change but still possible.
private const float FEATURED_POLLING_INTERVAL_SECONDS = 300;

// WARNING: All dictionaries in ZandriaCreationsManager are private because they are not threadsafe. They must be
// accessed from within ZandriaCreationsManager and they must be locked before access.
Expand All @@ -343,7 +345,8 @@ public enum LoadStatus { NONE, LOADING_THUMBNAIL, LOADING_MODEL, FAILED, SUCCESS
private WorldSpace identityWorldSpace;

// When we last polled for updates to the menu.
private float timeLastPolled;
private float timeLikedLastPolled;
private float timeFeaturedLastPolled;

public AssetsServiceClient assetsServiceClient;
public static int MaxCreations => MAX_NUMBER_OF_PAGES * NUMBER_OF_CREATIONS_PER_PAGE;
Expand Down Expand Up @@ -414,17 +417,21 @@ void Update()
// Note: we don't poll the "Your models" section because (1) it's harder to optimize (it's not ordered
// by modified time) and (2) that flow is already covered in an ad-hoc way: we update the poly menu
// manually when the user saves a model.
if (PeltzerMain.Instance.polyMenuMain.PolyMenuIsActive() && Time.time - timeLastPolled > POLLING_INTERVAL_SECONDS)
if (PeltzerMain.Instance.polyMenuMain.PolyMenuIsActive() && Time.time - timeLikedLastPolled > LIKED_POLLING_INTERVAL_SECONDS)
{
if (loadsByType.ContainsKey(PolyMenuMain.CreationType.FEATURED))
{
Poll(PolyMenuMain.CreationType.FEATURED);
}
if (loadsByType.ContainsKey(PolyMenuMain.CreationType.LIKED) && OAuth2Identity.Instance.LoggedIn)
{
Poll(PolyMenuMain.CreationType.LIKED);
}
timeLastPolled = Time.time;
timeLikedLastPolled = Time.time;
}
if (PeltzerMain.Instance.polyMenuMain.PolyMenuIsActive() && Time.time - timeFeaturedLastPolled > FEATURED_POLLING_INTERVAL_SECONDS)
{
if (loadsByType.ContainsKey(PolyMenuMain.CreationType.FEATURED))
{
Poll(PolyMenuMain.CreationType.FEATURED);
}
timeFeaturedLastPolled = Time.time;
}
}

Expand Down

0 comments on commit a18182d

Please sign in to comment.