<!--#
Test type 3: Multiple database queries
TechEmpower Web Framework Benchmarks
-->
<!--#declaration
#include "world.h"

static char buffer[8192];
static UREDISClient_Base* rc;
static UVector<World*>* pvworld_query;

static void usp_fork_rquery()
{
   U_TRACE(5, "::usp_fork_rquery()")

   U_NEW(UREDISClient<UTCPSocket>, rc, UREDISClient<UTCPSocket>);

   if (rc->connect() == false)
      {
      U_WARNING("usp_fork_rquery(): %V", rc->UClient_Base::getResponse().rep);

      delete rc;
             rc = U_NULLPTR;

      return;
      }

   U_NEW(UVector<World*>, pvworld_query, UVector<World*>(500));
}

#ifdef DEBUG
static void usp_end_rquery()
{
   U_TRACE(5, "::usp_end_rquery()")

   if (pvworld_query)
      {
      delete rc;
      delete pvworld_query;
      }
}
#endif
-->
<!--#header
Content-Type: application/json
-->
<!--#code
World* pworld;
UStringRep* rep;
char* pbuffer = buffer;
int i, num_queries = UHTTP::getFormFirstNumericValue(1, 500);

(void) UClientImage_Base::wbuffer->reserve(36U * num_queries);

#ifdef AS_cpoll_cppsp_DO
USP_PUTS_CHAR('[');
#endif

for (i = 0; i < num_queries; ++i)
   {
   U_NEW(World, pworld, World);

   pvworld_query->push_back(pworld);

   u_put_unalignedp64(pbuffer, U_MULTICHAR_CONSTANT64(' ','w','o','r','l','d',':','\0'));

   pbuffer = u_num2str32(pworld->id = u_get_num_random(10000-1), pbuffer+7);
   }

(void) rc->mget(buffer, pbuffer-buffer);

i = 0;

while (true)
   {
   pworld = pvworld_query->at(i);

   rep = rc->vitem[i].rep;

   pworld->randomNumber = rep->strtoul();

#ifdef AS_cpoll_cppsp_DO
   USP_PRINTF("{\"id\":%u,\"randomNumber\":%v}", pworld->id, rep);
#endif

   if (++i == num_queries) break;

#ifdef AS_cpoll_cppsp_DO
   USP_PUTS_CHAR(',');
#endif
   }

#ifdef AS_cpoll_cppsp_DO
USP_PUTS_CHAR(']');
#else
USP_OBJ_JSON_stringify(*pvworld_query);
#endif
pvworld_query->clear();
-->
