mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-04-27 14:57:44 +00:00
batch land sql queries to 1 per ward instead of 60
This commit is contained in:
parent
14848ee955
commit
0d66bdd270
6 changed files with 66 additions and 38 deletions
|
@ -208,6 +208,10 @@ void Sapphire::Db::ZoneDbConnection::doPrepareStatements()
|
||||||
"SELECT LandIdent, ContainerId, ItemId, SlotId FROM houseiteminventory WHERE LandIdent = ?",
|
"SELECT LandIdent, ContainerId, ItemId, SlotId FROM houseiteminventory WHERE LandIdent = ?",
|
||||||
CONNECTION_SYNC );
|
CONNECTION_SYNC );
|
||||||
|
|
||||||
|
prepareStatement( LANDSET_SEL,
|
||||||
|
"SELECT * FROM land WHERE LandSetId = ?;",
|
||||||
|
CONNECTION_SYNC );
|
||||||
|
|
||||||
/*prepareStatement( LAND_INS,
|
/*prepareStatement( LAND_INS,
|
||||||
"INSERT INTO land ( LandSetId ) VALUES ( ? );",
|
"INSERT INTO land ( LandSetId ) VALUES ( ? );",
|
||||||
CONNECTION_BOTH );
|
CONNECTION_BOTH );
|
||||||
|
|
|
@ -81,6 +81,7 @@ namespace Sapphire::Db
|
||||||
LAND_INS,
|
LAND_INS,
|
||||||
LAND_SEL,
|
LAND_SEL,
|
||||||
LAND_UP,
|
LAND_UP,
|
||||||
|
LANDSET_SEL,
|
||||||
HOUSING_HOUSE_INS,
|
HOUSING_HOUSE_INS,
|
||||||
HOUSING_HOUSE_UP,
|
HOUSING_HOUSE_UP,
|
||||||
HOUSING_HOUSE_DEL,
|
HOUSING_HOUSE_DEL,
|
||||||
|
|
|
@ -42,12 +42,15 @@ bool Sapphire::HousingZone::init()
|
||||||
{
|
{
|
||||||
|
|
||||||
auto pDb = g_fw.get< Db::DbWorkerPool< Db::ZoneDbConnection > >();
|
auto pDb = g_fw.get< Db::DbWorkerPool< Db::ZoneDbConnection > >();
|
||||||
auto res = pDb->query( "SELECT * FROM landset WHERE landsetid = " + std::to_string( m_landSetId ) );
|
|
||||||
if( !res->next() )
|
|
||||||
{
|
{
|
||||||
pDb->directExecute( "INSERT INTO landset ( landsetid ) VALUES ( " + std::to_string( m_landSetId ) + " );" );
|
auto res = pDb->query( "SELECT * FROM landset WHERE landsetid = " + std::to_string( m_landSetId ) );
|
||||||
|
if( !res->next() )
|
||||||
|
{
|
||||||
|
pDb->directExecute( "INSERT INTO landset ( landsetid ) VALUES ( " + std::to_string( m_landSetId ) + " );" );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int housingIndex;
|
int housingIndex;
|
||||||
if( m_territoryTypeId == 339 )
|
if( m_territoryTypeId == 339 )
|
||||||
housingIndex = 0;
|
housingIndex = 0;
|
||||||
|
@ -61,25 +64,46 @@ bool Sapphire::HousingZone::init()
|
||||||
auto pExdData = g_fw.get< Data::ExdDataGenerated >();
|
auto pExdData = g_fw.get< Data::ExdDataGenerated >();
|
||||||
auto info = pExdData->get< Sapphire::Data::HousingLandSet >( housingIndex );
|
auto info = pExdData->get< Sapphire::Data::HousingLandSet >( housingIndex );
|
||||||
|
|
||||||
uint32_t landId;
|
auto stmt = pDb->getPreparedStatement( Db::LANDSET_SEL );
|
||||||
for( landId = 0; landId < 60; landId++ )
|
stmt->setUInt64( 1, m_landSetId );
|
||||||
{
|
auto res = pDb->query( stmt );
|
||||||
auto pLand = make_Land( m_territoryTypeId, getWardNum(), landId, m_landSetId, info );
|
|
||||||
m_landPtrMap[ landId ] = pLand;
|
|
||||||
|
|
||||||
if( auto house = pLand->getHouse() )
|
std::vector< QueuedLandInit > landInit;
|
||||||
{
|
|
||||||
registerHouseEntranceEObj( landId << 8 );
|
while( res->next() )
|
||||||
}
|
{
|
||||||
|
|
||||||
|
QueuedLandInit init;
|
||||||
|
init.m_landId = res->getUInt64( "LandId" );
|
||||||
|
init.m_type = static_cast< Common::LandType >( res->getUInt( "Type" ) );
|
||||||
|
init.m_size = res->getUInt( "Size" );
|
||||||
|
init.m_status = res->getUInt( "Status" );
|
||||||
|
init.m_currentPrice = res->getUInt( "LandPrice" );
|
||||||
|
init.m_ownerId = res->getUInt64( "OwnerId" );
|
||||||
|
init.m_houseId = res->getUInt64( "HouseId" );
|
||||||
|
|
||||||
|
landInit.push_back( init );
|
||||||
|
}
|
||||||
|
|
||||||
|
// nuke current query connection so the queries still in land don't fail
|
||||||
|
res.reset();
|
||||||
|
|
||||||
|
// spawn land
|
||||||
|
for( auto& init : landInit )
|
||||||
|
{
|
||||||
|
auto land = make_Land( m_territoryTypeId, getWardNum(), init.m_landId, m_landSetId, info );
|
||||||
|
land->init( init.m_type, init.m_size, init.m_status, init.m_currentPrice, init.m_ownerId, init.m_houseId );
|
||||||
|
|
||||||
|
m_landPtrMap[ init.m_landId ] = land;
|
||||||
|
|
||||||
|
if( init.m_houseId > 0 )
|
||||||
|
registerHouseEntranceEObj( init.m_landId );
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Sapphire::HousingZone::~HousingZone()
|
Sapphire::HousingZone::~HousingZone() = default;
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void Sapphire::HousingZone::onPlayerZoneIn( Entity::Player& player )
|
void Sapphire::HousingZone::onPlayerZoneIn( Entity::Player& player )
|
||||||
{
|
{
|
||||||
|
|
|
@ -53,6 +53,17 @@ namespace Sapphire
|
||||||
Entity::EventObjectPtr registerHouseEntranceEObj( uint8_t plotId );
|
Entity::EventObjectPtr registerHouseEntranceEObj( uint8_t plotId );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
struct QueuedLandInit
|
||||||
|
{
|
||||||
|
uint64_t m_landId;
|
||||||
|
Common::LandType m_type;
|
||||||
|
uint8_t m_size;
|
||||||
|
uint8_t m_status;
|
||||||
|
uint32_t m_currentPrice;
|
||||||
|
uint64_t m_ownerId;
|
||||||
|
uint64_t m_houseId;
|
||||||
|
};
|
||||||
|
|
||||||
using LandPtrMap = std::unordered_map< uint8_t, Sapphire::LandPtr >;
|
using LandPtrMap = std::unordered_map< uint8_t, Sapphire::LandPtr >;
|
||||||
const uint32_t m_landSetMax = 18;
|
const uint32_t m_landSetMax = 18;
|
||||||
LandPtrMap m_landPtrMap;
|
LandPtrMap m_landPtrMap;
|
||||||
|
|
|
@ -48,32 +48,20 @@ Sapphire::Land::Land( uint16_t territoryTypeId, uint8_t wardNum, uint8_t landId,
|
||||||
m_landIdent.wardNum = wardNum;
|
m_landIdent.wardNum = wardNum;
|
||||||
m_landIdent.worldId = 67; // todo: fix this
|
m_landIdent.worldId = 67; // todo: fix this
|
||||||
|
|
||||||
init();
|
m_minPrice = m_landInfo->minPrice[ m_landIdent.landId ];
|
||||||
|
m_maxPrice = m_landInfo->initialPrice[ m_landIdent.landId ];
|
||||||
}
|
}
|
||||||
|
|
||||||
Sapphire::Land::~Land() = default;
|
Sapphire::Land::~Land() = default;
|
||||||
|
|
||||||
void Sapphire::Land::init()
|
void Sapphire::Land::init( Common::LandType type, uint8_t size, uint8_t state, uint32_t currentPrice, uint64_t ownerId, uint64_t houseId )
|
||||||
{
|
{
|
||||||
// todo: move this loading logic outside of land and fetch all houses in 1 query
|
|
||||||
auto pDb = g_fw.get< Db::DbWorkerPool< Db::ZoneDbConnection > >();
|
|
||||||
auto res = pDb->query( "SELECT * FROM land WHERE LandSetId = " + std::to_string( m_landSetId ) + " "
|
|
||||||
"AND LandId = " + std::to_string( m_landIdent.landId ) );
|
|
||||||
|
|
||||||
// we're not going to be building the land table at runtime
|
m_type = type;
|
||||||
assert( res->next() );
|
m_size = size;
|
||||||
|
m_state = state;
|
||||||
m_type = static_cast< Common::LandType >( res->getUInt( "Type" ) );
|
m_currentPrice = currentPrice;
|
||||||
m_size = res->getUInt( "Size" );
|
m_ownerId = ownerId;
|
||||||
m_state = res->getUInt( "Status" );
|
|
||||||
m_currentPrice = res->getUInt( "LandPrice" );
|
|
||||||
m_ownerId = res->getUInt64( "OwnerId" );
|
|
||||||
m_minPrice = m_landInfo->minPrice[ m_landIdent.landId ];
|
|
||||||
m_maxPrice = m_landInfo->initialPrice[ m_landIdent.landId ];
|
|
||||||
|
|
||||||
auto houseId = res->getUInt( "HouseId" );
|
|
||||||
|
|
||||||
res.reset();
|
|
||||||
|
|
||||||
// fetch the house if we have one for this land
|
// fetch the house if we have one for this land
|
||||||
if( houseId > 0 )
|
if( houseId > 0 )
|
||||||
|
@ -123,7 +111,7 @@ void Sapphire::Land::init()
|
||||||
setupContainer( InventoryType::HousingInteriorPlacedItems1, m_maxPlacedInternalItems );
|
setupContainer( InventoryType::HousingInteriorPlacedItems1, m_maxPlacedInternalItems );
|
||||||
setupContainer( InventoryType::HousingInteriorStoreroom1, m_maxPlacedInternalItems );
|
setupContainer( InventoryType::HousingInteriorStoreroom1, m_maxPlacedInternalItems );
|
||||||
|
|
||||||
loadItemContainerContents();
|
// loadItemContainerContents();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sapphire::Land::loadItemContainerContents()
|
void Sapphire::Land::loadItemContainerContents()
|
||||||
|
|
|
@ -17,6 +17,7 @@ namespace Sapphire
|
||||||
|
|
||||||
Land( uint16_t zoneId, uint8_t wardNum, uint8_t landId, uint32_t landSetId, Sapphire::Data::HousingLandSetPtr info );
|
Land( uint16_t zoneId, uint8_t wardNum, uint8_t landId, uint32_t landSetId, Sapphire::Data::HousingLandSetPtr info );
|
||||||
virtual ~Land();
|
virtual ~Land();
|
||||||
|
void init( Common::LandType type, uint8_t size, uint8_t state, uint32_t currentPrice, uint64_t ownerId, uint64_t houseId );
|
||||||
|
|
||||||
using LandInventoryMap = std::unordered_map< uint16_t, ItemContainerPtr >;
|
using LandInventoryMap = std::unordered_map< uint16_t, ItemContainerPtr >;
|
||||||
|
|
||||||
|
@ -64,7 +65,6 @@ namespace Sapphire
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint32_t convertItemIdToHousingItemId( uint32_t itemId );
|
uint32_t convertItemIdToHousingItemId( uint32_t itemId );
|
||||||
void init();
|
|
||||||
uint32_t getNextHouseId();
|
uint32_t getNextHouseId();
|
||||||
|
|
||||||
Common::LandIdent m_landIdent;
|
Common::LandIdent m_landIdent;
|
||||||
|
|
Loading…
Add table
Reference in a new issue