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

Remove duplicates from MultiQuery #4286

Merged
merged 4 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
1 change: 1 addition & 0 deletions src/AppInstallerCLICore/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,7 @@ namespace AppInstaller::CLI
}

// Special handling for multi-query arguments:
execArgs.MakeMultiQueryContainUniqueValues();
execArgs.MoveMultiQueryToSingleQueryIfNeeded();
}

Expand Down
21 changes: 20 additions & 1 deletion src/AppInstallerCLICore/ExecutionArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,29 @@ namespace AppInstaller::CLI::Execution
return types;
}

// If the user passes the same value multiple times inside a MultiQuery, operations will be repeated
// Since there currently is not a way to include search options within a MultiQuery, processing duplicates
// does not make sense within a single invocation
void MakeMultiQueryContainUniqueValues()
{
auto itr = m_parsedArgs.find(Type::MultiQuery);

// If there is not a value in MultiQuery, or there is only one value, it is presumed to be unique
if (itr == m_parsedArgs.end() || itr->second.size() == 1)
{
return;
}

std::set<std::string> querySet;
std::vector<std::string> queryStrings = itr->second;
Trenly marked this conversation as resolved.
Show resolved Hide resolved

queryStrings.erase(std::remove_if(queryStrings.begin(), queryStrings.end(), [&](const std::string value) { return !querySet.insert(value).second; }), queryStrings.end());
m_parsedArgs[Type::MultiQuery].assign(queryStrings.begin(), queryStrings.end());
Trenly marked this conversation as resolved.
Show resolved Hide resolved
}

// If we get a single value for multi-query, we remove the argument and add it back as a single query.
// This way the rest of the code can assume that if there is a MultiQuery we will always have multiple values,
// and if there is a single one it will be in the Query type.
// This is the only case where we modify the parsed args from user input.
void MoveMultiQueryToSingleQueryIfNeeded()
{
auto itr = m_parsedArgs.find(Type::MultiQuery);
Expand Down
Loading