| 1682 | } |
| 1683 | |
| 1684 | int HTTPServer::queryResultsMsgPack(http::Context& ctx, reindexer::QueryResults& res, const IQRSerializingOption& qrOption, |
| 1685 | bool withColumns, int width) { |
| 1686 | int paramsToSend = 3; |
| 1687 | if (!res.GetAggregationResults().empty()) { |
| 1688 | ++paramsToSend; |
| 1689 | } |
| 1690 | if (!res.GetExplainResults().empty()) { |
| 1691 | ++paramsToSend; |
| 1692 | } |
| 1693 | if (withColumns) { |
| 1694 | ++paramsToSend; |
| 1695 | } |
| 1696 | if (qrOption.TotalCount().has_value()) { |
| 1697 | ++paramsToSend; |
| 1698 | } |
| 1699 | if (qrOption.QueryTotalCount().has_value()) { |
| 1700 | ++paramsToSend; |
| 1701 | } |
| 1702 | |
| 1703 | auto ser = makeRestrictedWrSerializer(ctx); |
| 1704 | MsgPackBuilder msgpackBuilder(ser, ObjType::TypeObject, paramsToSend); |
| 1705 | |
| 1706 | const auto offset = qrOption.ExternalOffset(); |
| 1707 | const auto limit = qrOption.ExternalLimit(); |
| 1708 | WrSerializer itemSer; |
| 1709 | std::vector<std::string> jsonData; |
| 1710 | if (withColumns) { |
| 1711 | size_t size = res.Count(); |
| 1712 | if (limit > offset && limit - offset < size) { |
| 1713 | size = limit - offset; |
| 1714 | } |
| 1715 | jsonData.reserve(size); |
| 1716 | } |
| 1717 | auto itemsArray = msgpackBuilder.Array(kParamItems, std::min(size_t(limit), size_t(res.Count() - offset))); |
| 1718 | auto it = res.begin() + offset; |
| 1719 | for (size_t i = 0; it != res.end() && i < limit; ++i, ++it) { |
| 1720 | auto err = it.GetMsgPack(ser, false); |
| 1721 | if (!err.ok()) { |
| 1722 | return msgpackStatus(ctx, http::HttpStatus(err)); |
| 1723 | } |
| 1724 | if (withColumns) { |
| 1725 | itemSer.Reset(); |
| 1726 | err = it.GetJSON(itemSer, false); |
| 1727 | if (!err.ok()) { |
| 1728 | return msgpackStatus(ctx, http::HttpStatus(err)); |
| 1729 | } |
| 1730 | jsonData.emplace_back(itemSer.Slice()); |
| 1731 | } |
| 1732 | } |
| 1733 | itemsArray.End(); |
| 1734 | |
| 1735 | if (!res.GetAggregationResults().empty()) { |
| 1736 | auto& aggs = res.GetAggregationResults(); |
| 1737 | auto aggregationsArray = msgpackBuilder.Array(kParamAggregations, aggs.size()); |
| 1738 | for (auto& agg : aggs) { |
| 1739 | agg.GetMsgPack(ser); |
| 1740 | } |
| 1741 | } |
nothing calls this directly
no test coverage detected