Skip to content
This repository has been archived by the owner on Sep 12, 2022. It is now read-only.

Commit

Permalink
speed tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
0xdeafcafe committed Oct 10, 2014
1 parent e8208f0 commit b95f1c0
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
7 changes: 4 additions & 3 deletions Branch.App/Controllers/SearchController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Web;
using System.Web.Mvc;
using Branch.App.Models;

Expand All @@ -11,13 +12,13 @@ public class SearchController : Controller
public ActionResult Index(string q)
{
if (String.IsNullOrEmpty(q))
throw new ArgumentException("yo, query can't be null/empty");
throw new HttpException(404, "yo, query can't be null/empty");

// find halo 4 players
var halo4ServiceRecord = GlobalStorage.H4Manager.GetPlayerServiceRecord(q);
var halo4ServiceRecord = GlobalStorage.H4Manager.GetPlayerServiceRecord(q, true);

// find halo reach players
var haloReachServiceRecord = GlobalStorage.HReachManager.GetPlayerServiceRecord(q);
var haloReachServiceRecord = GlobalStorage.HReachManager.GetPlayerServiceRecord(q, true);

// le render le model le
return View(new SearchViewModel(q, halo4ServiceRecord, haloReachServiceRecord));
Expand Down
5 changes: 5 additions & 0 deletions Branch.App/Web.config
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
<system.net>
<connectionManagement>
<add address="*" maxconnection="1000" />
</connectionManagement>
</system.net>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
Expand Down
4 changes: 3 additions & 1 deletion Branch.Azure/ServiceDefinition.csdef
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
<Setting name="SendGridPass" />
<Setting name="SendGridTo" />
<Setting name="StorageConnectionString" />
<Setting name="SqlServerConnectionString" />
<Setting name="SpartanTokenApi" />
</ConfigurationSettings>
<LocalResources>
</LocalResources>
</WorkerRole>
<WebRole name="Branch.App" vmsize="Small">
<WebRole name="Branch.App" vmsize="Medium">
<Sites>
<Site name="Web">
<Bindings>
Expand All @@ -33,6 +34,7 @@
<Setting name="SendGridPass" />
<Setting name="SendGridTo" />
<Setting name="StorageConnectionString" />
<Setting name="SqlServerConnectionString" />
<Setting name="SpartanTokenApi" />
</ConfigurationSettings>
<LocalResources>
Expand Down
7 changes: 6 additions & 1 deletion Branch.Core.Game.Halo4/Api/Manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,9 @@ public void GetChallenges()
/// Gets a Players Halo 4 Service Record
/// </summary>
/// <param name="gamertag">The players Xbox 360 Gamertag.</param>
/// <param name="takeCachedVersion">Tries to take the cached version. If no cached version is avaiable, gets from server.</param>
/// <returns>The raw JSON of their Service Record</returns>
public ServiceRecord GetPlayerServiceRecord(string gamertag)
public ServiceRecord GetPlayerServiceRecord(string gamertag, bool takeCachedVersion = false)
{
const BlobType blobType = BlobType.PlayerServiceRecord;
var escapedGamertag = EscapeGamertag(gamertag);
Expand All @@ -147,6 +148,10 @@ public ServiceRecord GetPlayerServiceRecord(string gamertag)
// Check if blob exists & expire date
if (blobValidity.Item1) return blobValidity.Item2;

// Do we take the cached version?
if (takeCachedVersion && blobValidity.Item2 != null)
return blobValidity.Item2;

// Try and get new blob
var url = PopulateUrl(UrlFromIds(EndpointType.ServiceList, "GetServiceRecord"),
new Dictionary<string, string> {{"gamertag", gamertag}});
Expand Down
7 changes: 6 additions & 1 deletion Branch.Core.Game.HaloReach/Api/Manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ public void GetMetadata()
/// Gets a Players Halo: Reach Service Record
/// </summary>
/// <param name="gamertag">The players Xbox 360 Gamertag.</param>
/// <param name="takeCachedVersion">Tries to take the cached version. If no cached version is avaiable, gets from server.</param>
/// <returns>Retuens a <see cref="ServiceRecord"/> model.</returns>
public ServiceRecord GetPlayerServiceRecord(string gamertag)
public ServiceRecord GetPlayerServiceRecord(string gamertag, bool takeCachedVersion = false)
{
const BlobType blobType = BlobType.PlayerServiceRecord;
var escapedGamertag = EscapeGamertag(gamertag);
Expand All @@ -76,6 +77,10 @@ public ServiceRecord GetPlayerServiceRecord(string gamertag)
// Check if blob exists & expire date
if (blobValidity.Item1) return blobValidity.Item2;

// Do we take the cached version?
if (takeCachedVersion && blobValidity.Item2 != null)
return blobValidity.Item2;

// Try and get new blob
var endpoint = String.Format("player/details/byplaylist/{0}/{1}", ApiKey, gamertag);
var serviceRecordRaw = ValidateResponseAndGetRawText(UnauthorizedRequest(endpoint));
Expand Down

0 comments on commit b95f1c0

Please sign in to comment.