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

Performance improvements #3808

Merged
merged 21 commits into from
Nov 8, 2023
Merged
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Let internal property lookups handle missing manifest
JohnMcPMS committed Nov 4, 2023
commit 9789305ea170bd439ac3f4283addde62d93b5c6b
Original file line number Diff line number Diff line change
@@ -517,12 +517,6 @@ namespace AppInstaller::Repository::Microsoft::Schema::V1_0

std::optional<std::string> Interface::GetPropertyByManifestId(const SQLite::Connection& connection, SQLite::rowid_t manifestId, PackageVersionProperty property) const
{
if (!ManifestTable::ExistsById(connection, manifestId))
{
AICLI_LOG(Repo, Info, << "Did not find manifest by id: " << manifestId);
return {};
}

return GetPropertyByManifestIdInternal(connection, manifestId, property);
}

@@ -634,13 +628,13 @@ namespace AppInstaller::Repository::Microsoft::Schema::V1_0
switch (property)
{
case AppInstaller::Repository::PackageVersionProperty::Id:
return std::get<0>(ManifestTable::GetValuesById<IdTable>(connection, manifestId));
return ManifestTable::GetValueById<IdTable>(connection, manifestId);
case AppInstaller::Repository::PackageVersionProperty::Name:
return std::get<0>(ManifestTable::GetValuesById<NameTable>(connection, manifestId));
return ManifestTable::GetValueById<NameTable>(connection, manifestId);
case AppInstaller::Repository::PackageVersionProperty::Version:
return std::get<0>(ManifestTable::GetValuesById<VersionTable>(connection, manifestId));
return ManifestTable::GetValueById<VersionTable>(connection, manifestId);
case AppInstaller::Repository::PackageVersionProperty::Channel:
return std::get<0>(ManifestTable::GetValuesById<ChannelTable>(connection, manifestId));
return ManifestTable::GetValueById<ChannelTable>(connection, manifestId);
case AppInstaller::Repository::PackageVersionProperty::RelativePath:
return PathPartTable::GetPathById(connection, std::get<0>(ManifestTable::GetIdsById<PathPartTable>(connection, manifestId)));
default:
Original file line number Diff line number Diff line change
@@ -63,14 +63,18 @@ namespace AppInstaller::Repository::Microsoft::Schema::V1_0
SQLite::Statement ManifestTableGetIdsById_Statement(
const SQLite::Connection& connection,
SQLite::rowid_t id,
std::initializer_list<std::string_view> values)
std::initializer_list<std::string_view> values,
bool stepAndVerify)
{
SQLite::Builder::StatementBuilder builder;
builder.Select(values).From(s_ManifestTable_Table_Name).Where(SQLite::RowIDName).Equals(id);

SQLite::Statement result = builder.Prepare(connection);

THROW_HR_IF(E_NOT_SET, !result.Step());
if (stepAndVerify)
{
THROW_HR_IF(E_NOT_SET, !result.Step());
}

return result;
}
@@ -84,7 +88,8 @@ namespace AppInstaller::Repository::Microsoft::Schema::V1_0
const SQLite::Connection& connection,
SQLite::rowid_t id,
std::initializer_list<SQLite::Builder::QualifiedColumn> columns,
std::initializer_list<std::string_view> manifestColumnNames)
std::initializer_list<std::string_view> manifestColumnNames,
bool stepAndVerify)
{
THROW_HR_IF(E_UNEXPECTED, manifestColumnNames.size() != columns.size());

@@ -108,7 +113,10 @@ namespace AppInstaller::Repository::Microsoft::Schema::V1_0

SQLite::Statement result = builder.Prepare(connection);

THROW_HR_IF(E_NOT_SET, !result.Step());
if (stepAndVerify)
{
THROW_HR_IF(E_NOT_SET, !result.Step());
}

return result;
}
Original file line number Diff line number Diff line change
@@ -38,14 +38,16 @@ namespace AppInstaller::Repository::Microsoft::Schema::V1_0
SQLite::Statement ManifestTableGetIdsById_Statement(
const SQLite::Connection& connection,
SQLite::rowid_t id,
std::initializer_list<std::string_view> values);
std::initializer_list<std::string_view> values,
bool stepAndVerify = true);

// Gets the requested values for the manifest with the given rowid.
SQLite::Statement ManifestTableGetValuesById_Statement(
const SQLite::Connection& connection,
SQLite::rowid_t id,
std::initializer_list<SQLite::Builder::QualifiedColumn> columns,
std::initializer_list<std::string_view> manifestColumnNames);
std::initializer_list<std::string_view> manifestColumnNames,
bool stepAndVerify = true);

// Gets all values for rows that match the given ids.
SQLite::Statement ManifestTableGetAllValuesByIds_Statement(
@@ -140,13 +142,29 @@ namespace AppInstaller::Repository::Microsoft::Schema::V1_0
return details::ManifestTableGetIdsById_Statement(connection, id, { details::GetManifestTableColumnName<Tables>()...}).GetRow<typename Tables::id_t...>();
}

// Gets the id requested for the manifest with the given rowid, if it exists.
template <typename Table>
static std::optional<typename Table::id_t> GetIdById(const SQLite::Connection& connection, SQLite::rowid_t id)
{
auto statement = details::ManifestTableGetIdsById_Statement(connection, id, { details::GetManifestTableColumnName<Table>() }, false);
if (statement.Step()) { return statement.GetColumn<typename Table::id_t>(0); } else { return std::nullopt; }
Copy link
Member

Choose a reason for hiding this comment

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

nit: linebreaks

}

// Gets the values requested for the manifest with the given rowid.
template <typename... Tables>
static auto GetValuesById(const SQLite::Connection& connection, SQLite::rowid_t id)
{
return details::ManifestTableGetValuesById_Statement(connection, id, { SQLite::Builder::QualifiedColumn{ Tables::TableName(), Tables::ValueName() }... }, { details::GetManifestTableColumnName<Tables>()... }).GetRow<typename Tables::value_t...>();
}

// Gets the value requested for the manifest with the given rowid, if it exists.
template <typename Table>
static std::optional<typename Table::value_t> GetValueById(const SQLite::Connection& connection, SQLite::rowid_t id)
{
auto statement = details::ManifestTableGetValuesById_Statement(connection, id, { SQLite::Builder::QualifiedColumn{ Table::TableName(), Table::ValueName() } }, { details::GetManifestTableColumnName<Table>() }, false);
if (statement.Step()) { return statement.GetColumn<typename Table::value_t>(0); } else { return std::nullopt; }
}

// Gets the row ids and values for rows that match the given ids.
template <typename ValueTable, typename... IdTables>
static std::vector<std::pair<SQLite::rowid_t, typename ValueTable::value_t>> GetAllValuesByIds(const SQLite::Connection& connection, std::initializer_list<SQLite::rowid_t> ids)
Original file line number Diff line number Diff line change
@@ -80,8 +80,8 @@ namespace AppInstaller::Repository::Microsoft::Schema::V1_3
{
case AppInstaller::Repository::PackageVersionProperty::ManifestSHA256Hash:
{
SQLite::blob_t hash = std::get<0>(V1_0::ManifestTable::GetIdsById<HashVirtualTable>(connection, manifestId));
return hash.empty() ? std::optional<std::string>{} : Utility::SHA256::ConvertToString(hash);
std::optional<SQLite::blob_t> hash = V1_0::ManifestTable::GetIdById<HashVirtualTable>(connection, manifestId);
return (!hash || hash->empty()) ? std::optional<std::string>{} : Utility::SHA256::ConvertToString(hash.value());
}
default:
return V1_2::Interface::GetPropertyByManifestIdInternal(connection, manifestId, property);
Original file line number Diff line number Diff line change
@@ -173,9 +173,9 @@ namespace AppInstaller::Repository::Microsoft::Schema::V1_5
switch (property)
{
case AppInstaller::Repository::PackageVersionProperty::ArpMinVersion:
return std::get<0>(V1_0::ManifestTable::GetValuesById<ArpMinVersionVirtualTable>(connection, manifestId));
return V1_0::ManifestTable::GetValueById<ArpMinVersionVirtualTable>(connection, manifestId);
case AppInstaller::Repository::PackageVersionProperty::ArpMaxVersion:
return std::get<0>(V1_0::ManifestTable::GetValuesById<ArpMaxVersionVirtualTable>(connection, manifestId));
return V1_0::ManifestTable::GetValueById<ArpMaxVersionVirtualTable>(connection, manifestId);
default:
return V1_4::Interface::GetPropertyByManifestIdInternal(connection, manifestId, property);
}