Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize SQL Statements / result gathering #2007

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/cds_objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,12 @@ class CdsObject {
this->metaData = metaData;
}

/// \brief Set entire metadata dictionary by moving
void setMetaData(std::vector<std::pair<std::string, std::string>>&& metaData)
{
this->metaData = std::move(metaData);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if it's a good idea to have setters moving stuff.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not? Isn't this a very common pattern and one of the main reasons for move?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm nvm.

}

/// \brief Add a single metadata value.
void addMetaData(const metadata_fields_t key, const std::string& value)
{
Expand Down Expand Up @@ -330,6 +336,12 @@ class CdsObject {
resources = res;
}

/// \brief Set resources by move
void setResources(std::vector<std::shared_ptr<CdsResource>>&& res)
{
resources = std::move(res);
}

/// \brief Search resources for given handler id
bool hasResource(int id) const
{
Expand Down
29 changes: 17 additions & 12 deletions src/database/sql_database.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1380,26 +1380,29 @@ std::shared_ptr<CdsObject> SQLDatabase::createObjectFromRow(const std::unique_pt

auto metaData = retrieveMetaDataForObject(obj->getID());
if (!metaData.empty()) {
obj->setMetaData(metaData);
obj->setMetaData(std::move(metaData));
} else if (obj->getRefID() != CDS_ID_ROOT) {
metaData = retrieveMetaDataForObject(obj->getRefID());
if (!metaData.empty())
obj->setMetaData(metaData);
obj->setMetaData(std::move(metaData));
}

std::string auxdataStr = fallbackString(getCol(row, BrowseCol::Auxdata), getCol(row, BrowseCol::RefAuxdata));
std::map<std::string, std::string> aux = dictDecode(auxdataStr);
obj->setAuxData(aux);

bool resourceZeroOk = false;
auto resources = retrieveResourcesForObject(obj->getID());
if (!resources.empty()) {
obj->setResources(resources);
resourceZeroOk = true;
obj->setResources(std::move(resources));
} else if (obj->getRefID() != CDS_ID_ROOT) {
resources = retrieveResourcesForObject(obj->getRefID());
if (!resources.empty())
obj->setResources(resources);
if (!resources.empty()) {
resourceZeroOk = true;
obj->setResources(std::move(resources));
}
}
auto resourceZeroOk = !resources.empty();

obj->setVirtual((obj->getRefID() && obj->isPureItem()) || (obj->isItem() && !obj->isPureItem())); // gets set to true for virtual containers below

Expand Down Expand Up @@ -1475,19 +1478,21 @@ std::shared_ptr<CdsObject> SQLDatabase::createObjectFromSearchRow(const std::uni

auto metaData = retrieveMetaDataForObject(obj->getID());
if (!metaData.empty())
obj->setMetaData(metaData);
obj->setMetaData(std::move(metaData));

bool resourceZeroOk = false;
auto resources = retrieveResourcesForObject(obj->getID());
if (!resources.empty()) {
obj->setResources(resources);
resourceZeroOk = true;
obj->setResources(std::move(resources));
} else if (obj->getRefID() != CDS_ID_ROOT) {
resources = retrieveResourcesForObject(obj->getRefID());
if (!resources.empty())
obj->setResources(resources);
if (!resources.empty()) {
resourceZeroOk = true;
obj->setResources(std::move(resources));
}
}

auto resourceZeroOk = !resources.empty();

if (obj->isItem()) {
if (!resourceZeroOk)
throw_std_runtime_error("tried to create object without at least one resource");
Expand Down