Response time optimization – Getting record count based on Input Parameters

I’m trying to optimize the process of calculating count of records, based on variable input parameters. The whole proces spans several queries, functions and stored procedures.

1/ Basically, front-end sends a request to the DB (it calls a Stored procedure) with an input parameter (DataTable). This DataTable (input parameter collection) contains 1 to X records. Each record corresponds to one specific rule.

2/ SP receives the collection of rules (as a custom typed table) and iterates through them one by one. Each rule apart from other meta-data contains a name of a specific function that should be used in evaluating the said rule.

For every rule, the SP prepares a dynamic query wherein it calls the mentioned function with 3 input parameters.

a/ Custom type Memory Optimized Table (Hashed index) b/ collection of lookup values (usually INTs) that the SELECT query uses to filtr data. Ie. "Get me all records, that have fkKey in (x1, x2, x3)" c/ BIT determining if this is the first rule in the whole process.

Each function has an IF statement, that determines based on the c/ parameter if it should return "all" records that fullfill the input criteria (b/). Or if it should fullfill the criteria on top of joining the result of previous rule that is contained in the custom table (a/)

3/ Once the function is run, it’s result is INSERTed into a table variable called @tmpResult. @result is then compared to tmpResult and records that are not in the tmpResult are DELETEd from result.

  • @result is a table variable (custom memory optimized table type), that holds intermediate result during the whole SP execution. It is fully filled up on the first rule, every consequent rule only removes records from it.

4/ The cycle repeats for every rule until all of the rules are done. At the end, count is called on the records in @result and returned as a result of SP.

Few things to take into account:

  • There are dozens of different types of rules. And the list of rules only grows bigger over time. That’s why dynamic query is used.
  • The most effective way to temporarily store records between individual rule execution so far proved to be custom Memory-Optimized table type. We tried a lot of things, but this one seems to be the fastest.
  • The number of records that are usually returned for 1 single rule is roughly somewhere between 100 000 and 3 000 000. That’s why a bucket_size of 5 000 000 for the HASHed temporary tables is used. And even though we tried nonclustered index, it was slower than that HASH.
  • The input collection of rules can vary strongly. There can be anything from 1 rule up to dozens of rules used at once.
  • Most every rules can be defined with at minimum 2 lookup values .. at most with dozens or in a few cases even hundred values. For a better understanding of rules, here are some examples:

Rule1Color, {1, 5, 7, 12} Rule2Size, {100, 200, 300} Rule3Material, {22, 23, 24}

Basically every rule is specified by it’s Designation, which corresponds to a specific Function. And by it’s collection of Lookup values. The possible lookup values differ based on the designation.

What we have done to optimize the process so far:

  • Where big number of records need to be temporarily stored, we use Memory-Optimized variable tables (also tried with temp ones, but it was basically same when using Memory-Optimized variants).
  • We strongly reduced and optimized the source tables the SELECT statements are run against.

Currently, the overal load is somewhat balanced 50/50 between I/O costs pertaining to SELECT statements and manipulation with records between temporary tables. Which is frankly not so good .. ideally the only bottleneck should be the I/O operations, but so far we were not able to come up with a better solution since the whole process has a lot of variability.

I will be happy for any idea you can throw my way. Of course feel free to ask questions if I failed to explain some part of the process adequately.

Thank you

If I ready a action (spell) in response to a companion’s attack, what is a fair GM rulling over the order of events?

In our campaign, I have a cleric who wished to use Ready an Action as his move. His idea behind this was that he wanted to ready Guiding Bolt and the condition he set was that, when one of the player (fighter) attacked a creature (one of 2 trolls), he would release the bolt beforehand. Therefore the figther would have advantage on her attack if the Guiding Bolt hit first.

I ruled that the fighter hit first, but I’m not so sure now – and feel like I was unfair in my ruling, maybe.

I can see both points of view:

  1. If I was the cleric readying my spell, I would cast the spell as soon as I noticed my fighter’s companion intention to attack a creature.

  2. But, also if I’m the fighter and I’m 5′ away from a creature, maybe my attack would land first, before the Guiding Bolt.

I would like some RAW guidance on this please. But, if not explicitly available, then a response with lived experience of a GM on a similar ruling to do with resolving oder of events.

Problems getting values from response from wp_remote_post

I am using wp_remote_post to send a request to a 3rd parti API. The response from the API looks something like:

{   status: 'a',   member_id: 12345678 } 

I understand that this is returned in the body of the array returned by wp_remote_post, but I’m having problems checking the value of status. here’s what I’ve got:

$  response = wp_remote_post($  url, $  myArr);  if ( is_wp_error( $  response ) ) {    $  error_message = $  response->get_error_message();    echo "Something went wrong: $  error_message"; } else {    echo 'Status: ' . json_decode($  response['body'])['status']; } 

This results in NOTHING being echoed. I know the call was successful because I receive the email notification from the 3rd party saying a member was just updated (and I can see the updates in their app). If I change echo 'Status: ' . json_decode($ response['body'])['status']; to echo '<pre>' . print_r($ response['body']) . '</pre>';, the object above is printed to screen, so I’m guessing I’m doing something wrong with json_decode.

here’s the full response, in case it helps:

Array (     [headers] => Requests_Utility_CaseInsensitiveDictionary Object         (             [data:protected] => Array                 (                     [accept-ranges] => bytes                     [age] => 0                     [content-type] => application/json; charset=utf8                     [date] => Fri, 16 Oct 2020 16:43:59 GMT                     [server] => Apache                     [via] => 1.1 varnish (Varnish/5.2)                     [x-varnish] => 1016917066                     [content-length] => 48                 )          )      [body] => {   "status": "a",    "member_id": 14958539705 }     [response] => Array         (             [code] => 200             [message] => OK         )      [cookies] => Array         (         )      [filename] =>      [http_response] => WP_HTTP_Requests_Response Object         (             [response:protected] => Requests_Response Object                 (                     [body] => {   "status": "a",    "member_id": 14958539705 }                     [raw] => HTTP/1.1 200 OK accept-ranges: bytes age: 0 Content-Type: application/json; charset=utf8 Date: Fri, 16 Oct 2020 16:43:59 GMT Server: Apache via: 1.1 varnish (Varnish/5.2) x-varnish: 1016917066 Content-Length: 48 Connection: Close  {   "status": "a",    "member_id": 14958539705 }                     [headers] => Requests_Response_Headers Object                         (                             [data:protected] => Array                                 (                                     [accept-ranges] => Array                                         (                                             [0] => bytes                                         )                                      [age] => Array                                         (                                             [0] => 0                                         )                                      [content-type] => Array                                         (                                             [0] => application/json; charset=utf8                                         )                                      [date] => Array                                         (                                             [0] => Fri, 16 Oct 2020 16:43:59 GMT                                         )                                      [server] => Array                                         (                                             [0] => Apache                                         )                                      [via] => Array                                         (                                             [0] => 1.1 varnish (Varnish/5.2)                                         )                                      [x-varnish] => Array                                         (                                             [0] => 1016917066                                         )                                      [content-length] => Array                                         (                                             [0] => 48                                         )                                  )                          )                      [status_code] => 200                     [protocol_version] => 1.1                     [success] => 1                     [redirects] => 0                     [url] =>                     [history] => Array                         (                         )                      [cookies] => Requests_Cookie_Jar Object                         (                             [cookies:protected] => Array                                 (                                 )                          )                  )              [filename:protected] =>              [data] =>              [headers] =>              [status] =>          )  ) 

Can anyone tell me the correct way to get the value of the status property returned in the body object of the response?

What’s behind the widespread negative response to Wild Sorcerers, and how can I ensure they’re fun at my table?

I’m just starting to get into D&D 5e. Magic classes in particular fascinate me, and the one that caught my eye the most is the wild sorcerer. Or, rather, the concept did. The mechanics of the design itself seem particularly lackluster when compared to every other magic class I’ve looked at.

After quite a bit of searching, it seems I’m not alone in this observation. All over the place, people insist that wild sorcerers are unbalanced/underwhelming/generally unwanted. But I haven’t really seen any explanations of what exactly makes them this way, compared to other classes.

I’m now looking at attempting to DM a game with a bunch of other newbies, and trying to figure the game out as a group. One of my players will likely want to play a wild sorcerer. I’m interested in seeing how that plays out in RAW, but more importantly, I want the players to have fun.

I’m new and inexperienced. What should I look out for in the Wild Sorcerer when considering balance, or fun? Are there any gaping flaws in practice for the wild sorcerer’s design?

Right now I’m considering using the existing mechanics, but supplementing them with a secondary system of character progression that slowly takes the sorcerer from fearing their magic that’s unpredictable, to having some, but not total, control over it. Basically there’s a chaos level that increases and decreases based on player ability/spell usage. High chaos means more wild surges, low means less. To get the most out of the design, you have to balance the chaos level (in theory).

Note, I’m well-aware that I should probably stick to RAW during the learning phase. But as someone that works in gaming, I’m also aware that mechanics typically function differently in practice than in theory, and so I want to be prepared for any known “in-practice” shortcomings.

It sounds like the main ones are how often a surge happens (GM overhead, chance of anything happening at all), and exactly what happens (more flavor vs more functionality, which is up to what you want from the game). Both answers were solid, but I’m going with Icy’s, since it approached the question more specifically targeting the Wild Sorcerer’s in-practice functionality with examples and edge cases.

Potential vulnerability in JSON response returning base 64 encoded image data, with the response being vulnerable to MIME sniffing

A JSON response in the API of a webapp is returning the base64 of a user-uploaded image, and there’s no X-Content-Type-Options Header to prevent MIME sniffing.

Could this be a potential vulnerability such as an XSS for the webapp by using steganography to edit the image with a payload, uploading it, and then MIME sniffing the JSON response? (or by any other means?)

What happens when you heal someone who is under the effects of Feign Death in response to Harm?

Here is a hypothetical scenario:

  1. Have Harm Cast on a player (reducing the maximum hit points)
  2. Cast Feign Death on the player, suppressing (not removing) the effects of the disease (not healing, but restoring the maximum hit points they have)
  3. Heal them (now that their maximum hit points are no longer reduced)
  4. Wake them up…

Does their hitpoint stay as they are (at maximum), or are they reduced back down (effectively taking damage again)?

Feign Death:

If the target is diseased or poisoned when you cast the spell, or becomes diseased or poisoned while under the spell’s effect, the disease and poison have no effect until the spell ends.


If the target fails the saving throw, its hit point maximum is reduced for 1 hour by an amount equal to the necrotic damage it took. Any effect that removes a disease allows a creature’s hit point maximum to return to normal before that time passes.

What is the highest average damage that a level 10 character can deal in response to being hit or damaged?


Typically, you deal damage by hitting the other guy with a stick (or a fireball) [citation needed]; however, spells like fire shield damage enemies who hit you:

In addition, whenever a creature within 5 feet of you hits you with a melee attack, the shield erupts with flame. The attacker takes 2d8 fire damage from a warm shield, or 2d8 cold damage from a cold shield.

Similarly, hellish rebuke allows you to damage enemies in response to them damaging you. Either way, the enemy wouldn’t have taken damage if they chose to just ignore you. This leads to my question: what is the highest average damage that a level 10 character can deal in response to being hit or damaged?



  • Level 10.
  • May use the PHB and one of the following: EE, MToF, SCAG, VGtM, or XGtE. This restriction extends to spells, as well. (If the spell is one your build allows you to copy from a scroll or spellbook, however, you may pick it from any of those sources.)
  • No variant rules besides multiclassing, feats, and variant human.
  • Up to three magic items from DMG Tables F or G with a maximum rarity of Rare.


  • Four encounters; Combat 1, Combat 2, Short Rest, Combat 3, Combat 4 (each of these events is separated by 30 minutes). The Short Rest is mandatory.
  • Each combat encounter has you face off against two earth elementals. These elementals do not have any damage vulnerabilities, damage immunities, or condition immunities. They keep their damage resistances.
  • Each combat lasts three rounds. All participants get a turn in each round.
  • Enemies move next to the PC and attack normally.
  • Enemies do not make opportunity attacks.
  • For the sake of simplicity, treat enemies and the PC as if they had infinite health.
  • You may not use the Ready action. (Mainly to prevent "I ready blight for when I get damaged" from being the best answer.)
  • Any spell or ability that lasts 10 minutes or longer may be activated before entering combat. Any spell or ability that lasts longer than 8 hours may be activated the day before.
  • You may not spend more than 100 gp on spells that consume costly material components. (So casting identify and find familiar is fine, because identify doesn’t consume its costly component, but casting glyph of warding is not.)
  • You never lose concentration as a result of taking damage.
  • Allies cannot help you, unless you summon/create them yourself (via conjure animals, animate dead, etc.)

Damage calculation

  • Damage should be the average damage per round over the course of the adventuring day.
  • Only count damage dealt to enemies (the earth elementals) in direct response to, and in the same turn as, being hit or damaged. Hellish rebuke is fine. The extra damage dealt by absorb elements is not. You may still deal damage in other ways (in case it’s necessary for setup), you just can’t count it in the total.