in FileInterner::FileInterner(Rcl::Doc) (query), declare the BeagleQueue static so that the cache persists between FileInterner objects

This commit is contained in:
dockes 2009-11-23 17:37:59 +00:00
parent 631d564123
commit 4cac0f56b5

View File

@ -348,6 +348,7 @@ FileInterner::FileInterner(const Rcl::Doc& idoc, RclConfig *cnf,
const string& td, int flags) const string& td, int flags)
: m_tdir(td) : m_tdir(td)
{ {
LOGDEB(("FileInterner::FileInterner(idoc)\n"));
initcommon(cnf, flags); initcommon(cnf, flags);
// We do insist on having an url... // We do insist on having an url...
@ -366,6 +367,7 @@ FileInterner::FileInterner(const Rcl::Doc& idoc, RclConfig *cnf,
backend = it->second; backend = it->second;
if (backend.empty() || !backend.compare("FS")) { if (backend.empty() || !backend.compare("FS")) {
// Filesystem document. Intern from file.
// The url has to be like file:// // The url has to be like file://
if (idoc.url.find("file://") != 0) { if (idoc.url.find("file://") != 0) {
LOGERR(("FileInterner: FS backend and non fs url: [%s]\n", LOGERR(("FileInterner: FS backend and non fs url: [%s]\n",
@ -375,35 +377,41 @@ FileInterner::FileInterner(const Rcl::Doc& idoc, RclConfig *cnf,
string fn = idoc.url.substr(7, string::npos); string fn = idoc.url.substr(7, string::npos);
struct stat st; struct stat st;
if (stat(fn.c_str(), &st) < 0) { if (stat(fn.c_str(), &st) < 0) {
LOGERR(("InternFile: cannot access document file: [%s]\n", LOGERR(("FileInterner:: cannot access document file: [%s]\n",
fn.c_str())); fn.c_str()));
return; return;
} }
init(fn, &st, cnf, td, flags, &idoc.mimetype); init(fn, &st, cnf, td, flags, &idoc.mimetype);
} else if (!backend.compare("BGL")) { } else if (!backend.compare("BGL")) {
// Retrieve from our webcache (beagle data) // Retrieve from our webcache (beagle data). There should
BeagleQueueIndexer beagler(cnf); // probably be a separate object type for readonly cache
// access (distinct from the one used for indexing).
// Anyway, we're not called in the same thread as indexing ops, and
// even, at worse, this would duplicate the memory used. The beagler
// object is created at the first call of this routine and deleted
// when the program exits.
static BeagleQueueIndexer beagler(cnf);
string data; string data;
Rcl::Doc dotdoc; Rcl::Doc dotdoc;
map<string,string>::const_iterator it = map<string,string>::const_iterator it =
idoc.meta.find(Rcl::Doc::keyudi); idoc.meta.find(Rcl::Doc::keyudi);
if (it == idoc.meta.end() || it->second.empty()) { if (it == idoc.meta.end() || it->second.empty()) {
LOGERR(("Internfile: no udi in idoc\n")); LOGERR(("FileInterner:: no udi in idoc\n"));
return; return;
} }
string udi = it->second; string udi = it->second;
if (!beagler.getFromCache(udi, dotdoc, data)) { if (!beagler.getFromCache(udi, dotdoc, data)) {
LOGINFO(("Internfile: failed fetch from Beagle cache for [%s]\n", LOGINFO(("FileInterner:: failed fetch from Beagle cache for [%s]\n",
udi.c_str())); udi.c_str()));
return; return;
} }
if (dotdoc.mimetype.compare(idoc.mimetype)) { if (dotdoc.mimetype.compare(idoc.mimetype)) {
LOGINFO(("Internfile: udi [%s], mimetype mismatch: in: [%s], bgl " LOGINFO(("FileInterner:: udi [%s], mimetp mismatch: in: [%s], bgl "
"[%s]\n", idoc.mimetype.c_str(), dotdoc.mimetype.c_str())); "[%s]\n", idoc.mimetype.c_str(), dotdoc.mimetype.c_str()));
} }
init(data, cnf, td, flags, dotdoc.mimetype); init(data, cnf, td, flags, dotdoc.mimetype);
} else { } else {
LOGERR(("InternFile: unknown backend: [%s]\n", backend.c_str())); LOGERR(("FileInterner:: unknown backend: [%s]\n", backend.c_str()));
return; return;
} }
} }