| 1747 | } |
| 1748 | |
| 1749 | int HTTPServer::queryResultsProtobuf(http::Context& ctx, reindexer::QueryResults& res, const IQRSerializingOption& qrOption, |
| 1750 | bool withColumns, int width) { |
| 1751 | auto ser = makeRestrictedWrSerializer(ctx); |
| 1752 | ProtobufBuilder protobufBuilder(ser); |
| 1753 | |
| 1754 | const auto offset = qrOption.ExternalOffset(); |
| 1755 | const auto limit = qrOption.ExternalLimit(); |
| 1756 | auto& lres = res.ToLocalQr(); |
| 1757 | WrSerializer itemSer; |
| 1758 | std::vector<std::string> jsonData; |
| 1759 | if (withColumns) { |
| 1760 | size_t size = res.Count(); |
| 1761 | if (limit > offset && limit - offset < size) { |
| 1762 | size = limit - offset; |
| 1763 | } |
| 1764 | jsonData.reserve(size); |
| 1765 | } |
| 1766 | for (size_t i = offset; i < lres.Count() && i < offset + limit; i++) { |
| 1767 | auto it = lres[i]; |
| 1768 | auto err = it.GetProtobuf(ser); |
| 1769 | if (!err.ok()) { |
| 1770 | return protobufStatus(ctx, http::HttpStatus(err)); |
| 1771 | } |
| 1772 | if (withColumns) { |
| 1773 | itemSer.Reset(); |
| 1774 | err = it.GetJSON(itemSer, false); |
| 1775 | if (!err.ok()) { |
| 1776 | return protobufStatus(ctx, http::HttpStatus(err)); |
| 1777 | } |
| 1778 | jsonData.emplace_back(itemSer.Slice()); |
| 1779 | } |
| 1780 | } |
| 1781 | |
| 1782 | const TagName aggregationField = kProtoQueryResultsFields.at(kParamAggregations); |
| 1783 | for (auto& agg : res.GetAggregationResults()) { |
| 1784 | auto aggregation = protobufBuilder.Object(aggregationField); |
| 1785 | agg.GetProtobuf(ser); |
| 1786 | aggregation.End(); |
| 1787 | } |
| 1788 | |
| 1789 | const TagName nsField = kProtoQueryResultsFields.at(kParamNamespaces); |
| 1790 | h_vector<std::string_view, 1> namespaces(res.GetNamespaces()); |
| 1791 | for (auto ns : namespaces) { |
| 1792 | protobufBuilder.Put(nsField, ns); |
| 1793 | } |
| 1794 | |
| 1795 | protobufBuilder.Put(kProtoQueryResultsFields.at(kParamCacheEnabled), res.IsCacheEnabled() && !res.IsWALQuery()); |
| 1796 | |
| 1797 | if (!res.GetExplainResults().empty()) { |
| 1798 | protobufBuilder.Put(kProtoQueryResultsFields.at(kParamExplain), res.GetExplainResults()); |
| 1799 | } |
| 1800 | |
| 1801 | if (auto totalCount = qrOption.TotalCount(); totalCount.has_value()) { |
| 1802 | protobufBuilder.Put(kProtoQueryResultsFields.at(kParamTotalItems), int64_t(*totalCount)); |
| 1803 | } |
| 1804 | if (auto queryTotalCount = qrOption.QueryTotalCount(); queryTotalCount.has_value()) { |
| 1805 | protobufBuilder.Put(kProtoQueryResultsFields.at(kParamQueryTotalItems), int64_t(*queryTotalCount)); |
| 1806 | } |
nothing calls this directly
no test coverage detected