mirror of https://gitee.com/bigwinds/arangodb
Do not store ptr to local options (#8884)
This commit is contained in:
parent
3d25e935aa
commit
5625b56edc
|
@ -58,6 +58,7 @@ static arangodb::velocypack::StringRef const cidRef("cid");
|
|||
|
||||
static std::unique_ptr<VPackAttributeTranslator> translator;
|
||||
static std::unique_ptr<VPackCustomTypeHandler>customTypeHandler;
|
||||
static VPackOptions optionsWithUniquenessCheck;
|
||||
|
||||
template<bool useUtf8, typename Comparator>
|
||||
int compareObjects(VPackSlice const& lhs,
|
||||
|
@ -197,6 +198,9 @@ void VelocyPackHelper::initialize() {
|
|||
// allow dumping of Object attributes in "arbitrary" order (i.e. non-sorted
|
||||
// order)
|
||||
VPackOptions::Defaults.dumpAttributesInIndexOrder = false;
|
||||
|
||||
::optionsWithUniquenessCheck = VPackOptions::Defaults;
|
||||
::optionsWithUniquenessCheck.checkAttributeUniqueness = true;
|
||||
|
||||
// run quick selfs test with the attribute translator
|
||||
TRI_ASSERT(VPackSlice(::translator->translate(StaticStrings::KeyString)).getUInt() ==
|
||||
|
@ -232,6 +236,11 @@ arangodb::velocypack::AttributeTranslator* VelocyPackHelper::getTranslator() {
|
|||
return ::translator.get();
|
||||
}
|
||||
|
||||
/// @brief return the (global) attribute translator instance
|
||||
arangodb::velocypack::Options* VelocyPackHelper::optionsWithUniquenessCheck() {
|
||||
return &::optionsWithUniquenessCheck;
|
||||
}
|
||||
|
||||
bool VelocyPackHelper::AttributeSorterUTF8::operator()(std::string const& l,
|
||||
std::string const& r) const {
|
||||
// use UTF-8-based comparison of attribute names
|
||||
|
|
|
@ -82,6 +82,8 @@ class VelocyPackHelper {
|
|||
static void disableAssemblerFunctions();
|
||||
|
||||
static arangodb::velocypack::AttributeTranslator* getTranslator();
|
||||
|
||||
static arangodb::velocypack::Options* optionsWithUniquenessCheck();
|
||||
|
||||
struct VPackHash {
|
||||
size_t operator()(arangodb::velocypack::Slice const&) const;
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include "Basics/StringBuffer.h"
|
||||
#include "Basics/StringUtils.h"
|
||||
#include "Basics/Utf8Helper.h"
|
||||
#include "Basics/VelocyPackHelper.h"
|
||||
#include "Logger/Logger.h"
|
||||
|
||||
using namespace arangodb;
|
||||
|
@ -294,4 +295,9 @@ double GeneralRequest::parsedValue(std::string const& key, double valueNotFound)
|
|||
}
|
||||
return valueNotFound;
|
||||
}
|
||||
|
||||
std::shared_ptr<VPackBuilder> GeneralRequest::toVelocyPackBuilderPtr() {
|
||||
auto* opts = VelocyPackHelper::optionsWithUniquenessCheck();
|
||||
return std::make_shared<VPackBuilder>(payload(opts), opts);
|
||||
};
|
||||
} // namespace arangodb
|
||||
|
|
|
@ -196,13 +196,7 @@ class GeneralRequest {
|
|||
/// @brief parsed request payload
|
||||
virtual VPackSlice payload(arangodb::velocypack::Options const* options = &VPackOptions::Defaults) = 0;
|
||||
|
||||
TEST_VIRTUAL std::shared_ptr<VPackBuilder> toVelocyPackBuilderPtr() {
|
||||
VPackOptions optionsWithUniquenessCheck = VPackOptions::Defaults;
|
||||
optionsWithUniquenessCheck.checkAttributeUniqueness = true;
|
||||
return std::make_shared<VPackBuilder>(payload(&optionsWithUniquenessCheck),
|
||||
&optionsWithUniquenessCheck);
|
||||
};
|
||||
|
||||
TEST_VIRTUAL std::shared_ptr<VPackBuilder> toVelocyPackBuilderPtr();
|
||||
std::shared_ptr<VPackBuilder> toVelocyPackBuilderPtrNoUniquenessChecks() {
|
||||
return std::make_shared<VPackBuilder>(payload());
|
||||
};
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "Basics/NumberUtils.h"
|
||||
#include "Basics/StaticStrings.h"
|
||||
#include "Basics/StringUtils.h"
|
||||
#include "Basics/VelocyPackHelper.h"
|
||||
|
||||
#include <velocypack/Parser.h>
|
||||
#include <velocypack/velocypack-aliases.h>
|
||||
|
@ -87,9 +88,7 @@ std::shared_ptr<VPackBuilder> SimpleHttpResult::getBodyVelocyPack(VPackOptions c
|
|||
|
||||
// Default case
|
||||
std::shared_ptr<VPackBuilder> SimpleHttpResult::getBodyVelocyPack() const {
|
||||
VPackOptions options;
|
||||
options.checkAttributeUniqueness = true;
|
||||
return getBodyVelocyPack(options);
|
||||
return getBodyVelocyPack(*VelocyPackHelper::optionsWithUniquenessCheck());
|
||||
}
|
||||
|
||||
std::string SimpleHttpResult::getResultTypeMessage() const {
|
||||
|
|
Loading…
Reference in New Issue