0

I'm developing an API which searches for player cards to buy in FIFA 14.

I'm making 600 individual requests per minute for around 15 different Players spread over 3 different pages with each individual request returning up to a maximum of 50 results each time.

Each page performs a query to a table (lowestBuyNowPrice) that I've created that updates every 10 minutes with the lowest buy now price available on the market and I compare this value with the value of the current result.

However I've been buying cards for 2 or 3 times more than what the value in the lowestBuyNowPrice table is which should never happen.

I've set up a couple of other tables to try and figure out what was happening and it looks as though the queries are returning the results for a different player ID than the one that it should.

<cfscript>

// SEARCH FOR PLAYER
Variables.doSearch = Application.cfcs.Search.doPlayerSearch(Variables.search2PlayerID,0,"",0,0,0,0,0,Variables.searchPhishingKey,Variables.searchSessionKey);
Variables.searchResults = DeserializeJSON(Variables.doSearch.FileContent);
Variables.numResults = ArrayLen(Variables.searchResults.auctionInfo);
</cfscript>

<!--- GET LATEST LOWEST BIN PRICE --->
<cfquery name="qryBINPrice" datasource="sfadb">
SELECT assetID,playerPosition,lowestBIN FROM FUT14PlayerBIN WHERE binID IN (SELECT MAX(binID) AS binID FROM FUT14PlayerBIN WHERE assetID = #Variables.search2PlayerID# GROUP BY assetID,playerPosition)
</cfquery>

<cfscript>

    // LOOP ROUND RESULTS
    for (i=1; i<=Variables.numResults; i++) {

        // IF ASSET ID OF CURRENT CARD IS SAME AS ONE SEARCHING FOR
        if (Variables.searchResults.auctionInfo[i].itemData.assetID EQ Variables.search2PlayerID) {

            // DEFAULT BUY CARD VARIABLE
            Variables.buyCard = 0;

            // GET POSITION AND STYLE BIN
            Variables.getLowestBIN = Application.cfcs.Player.QoQ(qryBINPrice,"lowestBIN","playerPosition = '#Variables.searchResults.auctionInfo[i].itemData.preferredPosition#'");

            // IF LOWEST BIN RECORD EXISTS
            if (Variables.getLowestBin.RecordCount GT 0) {
                // SET LATEST LOWEST BIN PRICE
                Variables.lowestBIN = getLowestBIN.lowestBIN;

                // SET BUYING PRICE
                Variables.buyingPrice = Variables.lowestBIN * 0.9;

                // IF BIN PRICE SET AND IS LESS THAN SET BUYING PRICE
                if (Variables.searchResults.auctionInfo[i].buyNowPrice GT 0 AND Variables.searchResults.auctionInfo[i].buyNowPrice LTE Variables.buyingPrice) {
                    Variables.timeLeft = Variables.searchResults.auctionInfo[i].expires;
                    Variables.auctionEnds = DateAdd("s",timeLeft,Now());
                    Variables.insStuff = Application.cfcs.Bid.insStuff(Variables.searchResults.auctionInfo[i].itemData.assetID,Variables.searchResults.auctionInfo[i].itemData.preferredPosition,Variables.searchResults.auctionInfo[i].itemData.playStyle,Variables.lowestBIN,Variables.binPrice,Variables.startPrice,Variables.basePrice,Variables.buyingPrice,qryBINPrice.assetID,Variables.searchResults.auctionInfo[i].buyNowPrice);
                    Variables.doBuyCard = Application.cfcs.Bid.doBIN(Variables.searchResults.auctionInfo[i].tradeID,Variables.searchResults.auctionInfo[i].buyNowPrice,Variables.startPrice,Variables.binPrice,Variables.searchResults.auctionInfo[i].itemData.ID,Variables.searchResults.auctionInfo[i].itemData.assetID,Variables.searchResults.auctionInfo[i].itemData.resourceID,Variables.searchResults.auctionInfo[i].itemData.cardSubTypeID,Variables.searchResults.auctionInfo[i].itemData.playStyle,Variables.searchResults.auctionInfo[i].itemData.preferredPosition,Variables.searchResults.auctionInfo[i].startingBid,Variables.searchResults.auctionInfo[i].buyNowPrice,Variables.lowestBIN,Variables.searchResults.auctionInfo[i].currentBid,Variables.searchResults.auctionInfo[i].itemData.discardValue,Variables.auctionEnds);
                }
            }
        }
    }
}
</cfscript>

This is probably due to the volume of requests being made in such a short time but I have no idea how I can amend this to ensure that the correct record is always returned?

Anyone any ideas?

CPB07
  • 679
  • 3
  • 13
  • 23
  • 4
    It's hard to help without seeing any code. – Miguel-F Oct 25 '13 at 14:10
  • @Miguel-F OP updated with code – CPB07 Oct 25 '13 at 14:29
  • 1
    **Application.cfcs.Search.doPlayerSearch** Without reviewing the code, are all of your function variables properly `var/local` scoped - including query names? Since the components are stored in a shared scope, improper scoping of function local variables could definitely cause weird threading problems. – Leigh Oct 25 '13 at 14:45
  • The results returned from Search.doPlayerSearch are 100% correct, it's definitely something to do with the CFQuery. I'm thinking that because there could be several queries being called at the same time with nothing but the asset ID being different that it is returning the wrong query to the wrong request but is there a way I can ensure each query returns to its original requester? – CPB07 Oct 25 '13 at 14:54
  • 1
    Actually - with the CFQuery having the same name on each page could this be causing the issue? – CPB07 Oct 25 '13 at 14:55
  • I'm having a hard time following your scenario. You say that the page is updated every 10 minutes. Obviously the table can change during that time frame from other bidders. It looks like you are then performing a QoQ to get the lowest bid but that query is from the in-memory query that may have run 10 minutes ago. Right?? – Miguel-F Oct 25 '13 at 15:02
  • @CPB07 - No, I was not referring to the queries on the page above, rather any queries/variables inside your Application scoped functions. However, that was just an off-the-cuff observation as its a common gotcha when using application scoped components. I have not reviewed the code in any depth. – Leigh Oct 25 '13 at 15:19
  • No it's the table that updates every 10 minutes. The page will update every 400 milliseconds. The QoQ queries the CFQuery that is called a few lines above it. Does that help? – CPB07 Oct 25 '13 at 15:26
  • This tool is your friend - http://varscoper.riaforge.org/ – Matt Busche Oct 25 '13 at 15:32
  • @MattBusche Thanks - now to try and find a way of using it with CFEclipse! – CPB07 Oct 25 '13 at 16:00
  • @CPB07 there's a plugin available for Sublime Text. I have not tried using it with CFEclipse. – Matt Busche Oct 25 '13 at 16:01
  • @MattBusche Hmmmm no unscoped variables coming back when running varScoper which means I'm back at square one :\ – CPB07 Oct 28 '13 at 14:08

0 Answers0