1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "documentretrieverbase.h"
#include <vespa/document/repo/documenttyperepo.h>
#include <vespa/document/datatype/documenttype.h>
#include <vespa/vespalib/stllike/lrucache_map.hpp>
#include <vespa/vespalib/util/stringfmt.h>
using document::DocumentId;
using document::GlobalId;
namespace proton {
DocumentRetrieverBase::DocumentRetrieverBase(const DocTypeName &docTypeName, const document::DocumentTypeRepo &repo,
const IDocumentMetaStoreContext &meta_store, bool hasFields)
: IDocumentRetriever(),
_docTypeName(docTypeName),
_repo(repo),
_meta_store(meta_store),
_selectCache(256u),
_lock(),
_emptyDoc(),
_hasFields(hasFields)
{
const document::DocumentType * docType(_repo.getDocumentType(_docTypeName.getName()));
_emptyDoc = std::make_unique<document::Document>(_repo, *docType, DocumentId("id:empty:" + _docTypeName.getName() + "::empty"));
}
DocumentRetrieverBase::~DocumentRetrieverBase() = default;
void
DocumentRetrieverBase::getBucketMetaData(const storage::spi::Bucket &bucket,
search::DocumentMetaData::Vector &result) const
{
_meta_store.getReadGuard()->get().getMetaData(bucket, result);
}
search::DocumentMetaData
DocumentRetrieverBase::getDocumentMetaData(const DocumentId &id) const {
return _meta_store.getReadGuard()->get().getMetaData(id.getGlobalId());
}
CachedSelect::SP
DocumentRetrieverBase::parseSelect(const vespalib::string &selection) const
{
{
std::lock_guard<std::mutex> guard(_lock);
if (_selectCache.hasKey(selection))
return _selectCache[selection];
}
auto nselect = std::make_shared<CachedSelect>();
nselect->set(selection, _docTypeName.getName(), *_emptyDoc, getDocumentTypeRepo(), getAttrMgr(), _hasFields);
std::lock_guard<std::mutex> guard(_lock);
if (_selectCache.hasKey(selection))
return _selectCache[selection];
_selectCache.insert(selection, nselect);
return nselect;
}
} // namespace proton
|