Skip to content

Commit

Permalink
initial sonarcloud
Browse files Browse the repository at this point in the history
  • Loading branch information
Qup42 committed Feb 12, 2025
1 parent 9167809 commit 5cf80c3
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 66 deletions.
14 changes: 6 additions & 8 deletions src/engine/SPARQLProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ class SPARQLProtocol {
if (isContainedExactlyOnce("graph") &&
isContainedExactlyOnce("default")) {
throw std::runtime_error(
"Parameters \"graph\" and \"default\" must "
"not be set at the same time.");
R"(Parameters "graph" and "default" must not be set at the same time.)");
}

Check warning on line 61 in src/engine/SPARQLProtocol.h

View check run for this annotation

Codecov / codecov/patch

src/engine/SPARQLProtocol.h#L59-L61

Added lines #L59 - L61 were not covered by tests
AD_CORRECTNESS_CHECK(
std::holds_alternative<None>(parsedRequest.operation_));
Expand All @@ -78,12 +77,11 @@ class SPARQLProtocol {
auto checkUnsupportedGraphStoreContentType =
[&isGraphStoreOperation](std::string_view contentType,
std::string_view unsupportedType) {
if (isGraphStoreOperation()) {
if (contentType.starts_with(unsupportedType)) {
throw std::runtime_error(
absl::StrCat("Unsupported Content type \"", contentType,
"\" for Graph Store protocol."));
}
if (isGraphStoreOperation() &&
contentType.starts_with(unsupportedType)) {
throw std::runtime_error(
absl::StrCat("Unsupported Content type \"", contentType,
"\" for Graph Store protocol."));
}
};
auto addToDatasetClausesIfOperationIs =
Expand Down
111 changes: 53 additions & 58 deletions src/engine/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,34 +397,32 @@ Awaitable<void> Server::process(
const Operation& op, auto opFieldString,
std::function<bool(const ParsedQuery&)> pred,
std::string msg) -> Awaitable<void> {
if (auto timeLimit = co_await verifyUserSubmittedQueryTimeout(
checkParameter("timeout", std::nullopt), accessTokenOk, request,
send)) {
ad_utility::websocket::MessageSender messageSender = createMessageSender(
queryHub_, request, std::invoke(opFieldString, op));
auto [parsedOperation, qec, cancellationHandle,
cancelTimeoutOnDestruction] =
parseOperation(messageSender, parameters, op, timeLimit.value());
if (pred(parsedOperation)) {
throw std::runtime_error(
absl::StrCat(msg, parsedOperation._originalString));
}
if constexpr (std::is_same_v<Operation, Query>) {
co_return co_await processQuery(parameters, std::move(parsedOperation),
requestTimer, cancellationHandle, qec,
std::move(request), send,
timeLimit.value());
} else {
static_assert(std::is_same_v<Operation, Update>);
co_return co_await processUpdate(
std::move(parsedOperation), requestTimer, cancellationHandle, qec,
std::move(request), send, timeLimit.value());
}
} else {
auto timeLimit = co_await verifyUserSubmittedQueryTimeout(
checkParameter("timeout", std::nullopt), accessTokenOk, request, send);

Check warning on line 401 in src/engine/Server.cpp

View check run for this annotation

Codecov / codecov/patch

src/engine/Server.cpp#L400-L401

Added lines #L400 - L401 were not covered by tests
if (!timeLimit.has_value()) {
// If the optional is empty, this indicates an error response has been
// sent to the client already. We can stop here.
co_return;
}
ad_utility::websocket::MessageSender messageSender =
createMessageSender(queryHub_, request, std::invoke(opFieldString, op));
auto [parsedOperation, qec, cancellationHandle,
cancelTimeoutOnDestruction] =
parseOperation(messageSender, parameters, op, timeLimit.value());

Check warning on line 411 in src/engine/Server.cpp

View check run for this annotation

Codecov / codecov/patch

src/engine/Server.cpp#L407-L411

Added lines #L407 - L411 were not covered by tests
if (pred(parsedOperation)) {
throw std::runtime_error(
absl::StrCat(msg, parsedOperation._originalString));
}
if constexpr (std::is_same_v<Operation, Query>) {
co_return co_await processQuery(
parameters, std::move(parsedOperation), requestTimer,
cancellationHandle, qec, std::move(request), send, timeLimit.value());
} else {
static_assert(std::is_same_v<Operation, Update>);
co_return co_await processUpdate(
std::move(parsedOperation), requestTimer, cancellationHandle, qec,
std::move(request), send, timeLimit.value());
}

Check warning on line 425 in src/engine/Server.cpp

View check run for this annotation

Codecov / codecov/patch

src/engine/Server.cpp#L413-L425

Added lines #L413 - L425 were not covered by tests
};
auto visitQuery = [&visitOperation](const Query& query) -> Awaitable<void> {
return visitOperation(
Expand All @@ -444,44 +442,41 @@ Awaitable<void> Server::process(
[&send, &request, &checkParameter, &accessTokenOk, &parameters,
&requireValidAccessToken, this,
&requestTimer](const GraphStoreOperation& operation) -> Awaitable<void> {
if (auto timeLimit = co_await verifyUserSubmittedQueryTimeout(
checkParameter("timeout", std::nullopt), accessTokenOk, request,
send)) {
// TODO: verify that an empty string here results in a random id
ad_utility::websocket::MessageSender messageSender =
createMessageSender(queryHub_, request, "");
auto [cancellationHandle, cancelTimeoutOnDestruction] =
setupCancellationHandle(messageSender.getQueryId(),
timeLimit.value());
auto [pinSubtrees, pinResult] = determineResultPinning(parameters);
LOG(INFO) << "Processing a SPARQL Graph Store HTTP request:"
<< (pinResult ? " [pin result]" : "")
<< (pinSubtrees ? " [pin subresults]" : "") << std::endl;
QueryExecutionContext qec(
index_, &cache_, allocator_, sortPerformanceEstimator_,
std::ref(messageSender), pinSubtrees, pinResult);
ParsedQuery parsedOperation =
GraphStoreProtocol::transformGraphStoreProtocol(operation, request);

if (parsedOperation.hasUpdateClause()) {
requireValidAccessToken("SPARQL Update");

co_return co_await processUpdate(
std::move(parsedOperation), requestTimer, cancellationHandle, qec,
std::move(request), send, timeLimit.value());

} else {
co_return co_await processQuery(parameters, std::move(parsedOperation),
requestTimer, cancellationHandle, qec,
std::move(request), send,
timeLimit.value());
}
} else {
// TODO: comment from last PR
auto timeLimit = co_await verifyUserSubmittedQueryTimeout(
checkParameter("timeout", std::nullopt), accessTokenOk, request, send);

Check warning on line 446 in src/engine/Server.cpp

View check run for this annotation

Codecov / codecov/patch

src/engine/Server.cpp#L441-L446

Added lines #L441 - L446 were not covered by tests
if (!timeLimit.has_value()) {
// If the optional is empty, this indicates an error response has been
// sent to the client already. We can stop here.
co_return;
}

Check warning on line 451 in src/engine/Server.cpp

View check run for this annotation

Codecov / codecov/patch

src/engine/Server.cpp#L450-L451

Added lines #L450 - L451 were not covered by tests

// TODO: verify that an empty string here results in a random id
ad_utility::websocket::MessageSender messageSender =
createMessageSender(queryHub_, request, "");
auto [cancellationHandle, cancelTimeoutOnDestruction] =
setupCancellationHandle(messageSender.getQueryId(), timeLimit.value());
auto [pinSubtrees, pinResult] = determineResultPinning(parameters);
LOG(INFO) << "Processing a SPARQL Graph Store HTTP request:"

Check warning on line 459 in src/engine/Server.cpp

View check run for this annotation

Codecov / codecov/patch

src/engine/Server.cpp#L454-L459

Added lines #L454 - L459 were not covered by tests
<< (pinResult ? " [pin result]" : "")
<< (pinSubtrees ? " [pin subresults]" : "") << std::endl;
QueryExecutionContext qec(index_, &cache_, allocator_,
sortPerformanceEstimator_,
std::ref(messageSender), pinSubtrees, pinResult);
ParsedQuery parsedOperation =
GraphStoreProtocol::transformGraphStoreProtocol(operation, request);

Check warning on line 466 in src/engine/Server.cpp

View check run for this annotation

Codecov / codecov/patch

src/engine/Server.cpp#L462-L466

Added lines #L462 - L466 were not covered by tests

if (parsedOperation.hasUpdateClause()) {
requireValidAccessToken("SPARQL Update");

Check warning on line 469 in src/engine/Server.cpp

View check run for this annotation

Codecov / codecov/patch

src/engine/Server.cpp#L469

Added line #L469 was not covered by tests

co_return co_await processUpdate(
std::move(parsedOperation), requestTimer, cancellationHandle, qec,
std::move(request), send, timeLimit.value());

Check warning on line 473 in src/engine/Server.cpp

View check run for this annotation

Codecov / codecov/patch

src/engine/Server.cpp#L471-L473

Added lines #L471 - L473 were not covered by tests

} else {
co_return co_await processQuery(
parameters, std::move(parsedOperation), requestTimer,
cancellationHandle, qec, std::move(request), send, timeLimit.value());
}
};

Check warning on line 480 in src/engine/Server.cpp

View check run for this annotation

Codecov / codecov/patch

src/engine/Server.cpp#L475-L480

Added lines #L475 - L480 were not covered by tests
auto visitNone = [&response, &send,
&request](const None&) -> Awaitable<void> {
Expand Down

0 comments on commit 5cf80c3

Please sign in to comment.