0

Having a weird issue. A user logs in and I assign their pricing discount matrix as a query to a session variable. Then on the product pages I lookup their discount based on the products Pricing Group. This code has been working fine and continues to work for all users but this one in particular. So this is the scenario.

Login process sets this based on some data from a database <cfset SESSION.Vendor.PriceMatrix = #qryPriceMatrix# />

The query data would look something like this. So two columns.

| Discount | VendorCategory |
|----------|----------------|
|0.2       |    SWIPES      |
|0.2       |    TANTUS      |
|0.2       |    TOPCO       |
|0.2       |    VOODOO      |

Then on the product pages I simply query that session variable like so.

<cfquery name="GetYourPrice" dbtype="query">
    SELECT Discount FROM SESSION.Vendor.PriceMatrix
    WHERE VendorCategory = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#PricingGroup#" maxlength="20">
</cfquery>

The issue I am having is immediately following this query of the session variable it sets all of the values of the Discount column in the session variable to 0 like so.

| Discount | VendorCategory |
|----------|----------------|
|0         |    SWIPES      |
|0         |    TANTUS      |
|0         |    TOPCO       |
|0         |    VOODOO      |

I have no idea why or how this is happening since I would think in order for this to happen I would have to set the session variable but there is no cfset statement. Again this code works fine on all the other user accounts. Has anyone ever run into something similar? A query of a session var containing a query that then sets the first column to zeros?

Renshi
  • 77
  • 7

1 Answers1

1

this code works fine on all the other user accounts

Are you 100% sure about that? Odds are this is just the first account where this has been reported. Feels like a memory leak issue of sorts. If you're dealing with CFCs cached in applicaiton or session scopes, are all of the function variables local or var scoped to their functions?

If there's any code that sets a default value of 0 for every VendorDiscount in a query, change 0 to -1 and see if that's the code that getting called incorrectly.

How often are users logged into the system and not purchasing anything? If not very often, then you're adding to session memory with little ROI. Personally, I wouldn't cache this list of discounts. I would just query the DB and have it return the full price, discount amount and adjusted price in the main query.

Adrian J. Moreno
  • 14,350
  • 1
  • 37
  • 44
  • Yeah, that sounds suspiciously like race conditions due to bad scoping. Agreed that caching probably doesn't buy much here either. – SOS Aug 31 '21 at 21:07
  • I think the only way to be sure this is not a problem is to move the Session var containing their discounts into a database table. Seems the performance will be pretty close to the same as querying the session var as opposed to the database table. Only talking about like 150 rows per user. – Renshi Aug 31 '21 at 22:16
  • Using database queries sounds like the better option. But I'm curious, does it happen to this user _every_ time? What's the data type of the Discount column before an after? Tbh it is a stretch, but since you mentioned _all_ of the values were 0, I wondered if it was a casting/truncation issue – SOS Sep 01 '21 at 00:09
  • 1
    I have seen weird things happen with data when using query of queries. So, I would not be surprised if that was part of the cause. There is a way to make this more efficient. Don't put the query in session, create a structure where the vendorCategory is the key and discount is the value then you can look to see if a key exists in that struct and apply it if it does rather than doing a query of queries. – Scott Stroz Sep 01 '21 at 11:35