Use a shared_ptr to make sure that the rcldb referenced by the current query remains valid

This commit is contained in:
Jean-Francois Dockes
2019-04-11 15:05:44 +02:00
parent 1a1e59520d
commit 9e61f25b17
13 changed files with 48 additions and 54 deletions
+2 -2
View File
@@ -41,8 +41,8 @@ int DocSequence::getSeqSlice(int offs, int cnt, vector<ResListEntry>& result)
bool DocSequence::getEnclosing(Rcl::Doc& doc, Rcl::Doc& pdoc)
{
Rcl::Db *db = getDb();
if (db == 0) {
std::shared_ptr<Rcl::Db> db = getDb();
if (!db) {
LOGERR("DocSequence::getEnclosing: no db\n" );
return false;
}
+2 -3
View File
@@ -166,7 +166,7 @@ class DocSequence {
protected:
friend class DocSeqModifier;
virtual Rcl::Db *getDb() = 0;
virtual std::shared_ptr<Rcl::Db> getDb() = 0;
static std::mutex o_dblock;
static std::string o_sort_trans;
static std::string o_filt_trans;
@@ -247,8 +247,7 @@ public:
}
protected:
virtual Rcl::Db *getDb()
{
virtual std::shared_ptr<Rcl::Db> getDb() {
if (!m_seq)
return 0;
return m_seq->getDb();
+3 -7
View File
@@ -28,9 +28,10 @@
using std::list;
DocSequenceDb::DocSequenceDb(std::shared_ptr<Rcl::Query> q, const string &t,
DocSequenceDb::DocSequenceDb(std::shared_ptr<Rcl::Db> db,
std::shared_ptr<Rcl::Query> q, const string &t,
std::shared_ptr<Rcl::SearchData> sdata)
: DocSequence(t), m_q(q), m_sdata(sdata), m_fsdata(sdata),
: DocSequence(t), m_db(db), m_q(q), m_sdata(sdata), m_fsdata(sdata),
m_rescnt(-1),
m_queryBuildAbstract(true),
m_queryReplaceAbstract(false),
@@ -131,11 +132,6 @@ int DocSequenceDb::getFirstMatchPage(Rcl::Doc &doc, string& term)
return -1;
}
Rcl::Db *DocSequenceDb::getDb()
{
return m_q ? m_q->whatDb() : 0;
}
list<string> DocSequenceDb::expand(Rcl::Doc &doc)
{
std::unique_lock<std::mutex> locker(o_dblock);
+6 -2
View File
@@ -25,7 +25,8 @@
/** A DocSequence from a Db query */
class DocSequenceDb : public DocSequence {
public:
DocSequenceDb(std::shared_ptr<Rcl::Query> q, const string &t,
DocSequenceDb(std::shared_ptr<Rcl::Db> db,
std::shared_ptr<Rcl::Query> q, const string &t,
std::shared_ptr<Rcl::SearchData> sdata);
virtual ~DocSequenceDb() {}
virtual bool getDoc(int num, Rcl::Doc &doc, string * = 0);
@@ -58,8 +59,11 @@ class DocSequenceDb : public DocSequence {
virtual string title();
protected:
virtual Rcl::Db *getDb();
virtual std::shared_ptr<Rcl::Db> getDb() {
return m_db;
}
private:
std::shared_ptr<Rcl::Db> m_db;
std::shared_ptr<Rcl::Query> m_q;
std::shared_ptr<Rcl::SearchData> m_sdata;
std::shared_ptr<Rcl::SearchData> m_fsdata; // Filtered
+12 -17
View File
@@ -17,6 +17,8 @@
#ifndef _DOCSEQDOCS_H_INCLUDED_
#define _DOCSEQDOCS_H_INCLUDED_
#include <memory>
#include "docseq.h"
#include "rcldoc.h"
@@ -27,16 +29,13 @@ namespace Rcl {
/** A DocSequence that's just built from a bunch of docs */
class DocSequenceDocs : public DocSequence {
public:
DocSequenceDocs(Rcl::Db *d, const std::vector<Rcl::Doc> docs,
const string &t)
: DocSequence(t), m_db(d), m_docs(docs)
{
DocSequenceDocs(std::shared_ptr<Rcl::Db> d,
const std::vector<Rcl::Doc> docs, const string &t)
: DocSequence(t), m_db(d), m_docs(docs) {
}
virtual ~DocSequenceDocs()
{
virtual ~DocSequenceDocs() {
}
virtual bool getDoc(int num, Rcl::Doc &doc, string *sh = 0)
{
virtual bool getDoc(int num, Rcl::Doc &doc, string *sh = 0) {
if (sh)
*sh = string();
if (num < 0 || num >= int(m_docs.size()))
@@ -44,25 +43,21 @@ class DocSequenceDocs : public DocSequence {
doc = m_docs[num];
return true;
}
virtual int getResCnt()
{
virtual int getResCnt() {
return m_docs.size();
}
virtual string getDescription()
{
virtual string getDescription() {
return m_description;
}
void setDescription(const string& desc)
{
void setDescription(const string& desc) {
m_description = desc;
}
protected:
virtual Rcl::Db *getDb()
{
virtual std::shared_ptr<Rcl::Db> getDb() {
return m_db;
}
private:
Rcl::Db *m_db;
std::shared_ptr<Rcl::Db> m_db;
string m_description;
std::vector<Rcl::Doc> m_docs;
};
-5
View File
@@ -159,11 +159,6 @@ bool DocSequenceHistory::getDoc(int num, Rcl::Doc &doc, string *sh)
return ret;
}
Rcl::Db *DocSequenceHistory::getDb()
{
return m_db;
}
int DocSequenceHistory::getResCnt()
{
if (m_history.empty())
+8 -4
View File
@@ -19,6 +19,7 @@
#include <time.h>
#include <vector>
#include <memory>
#include "docseq.h"
#include "dynconf.h"
@@ -47,8 +48,9 @@ class RclDHistoryEntry : public DynConfEntry {
* metadata for an url key */
class DocSequenceHistory : public DocSequence {
public:
DocSequenceHistory(Rcl::Db *d, RclDynConf *h, const std::string &t)
: DocSequence(t), m_db(d), m_hist(h) {}
DocSequenceHistory(std::shared_ptr<Rcl::Db> db, RclDynConf *h,
const std::string &t)
: DocSequence(t), m_db(db), m_hist(h) {}
virtual ~DocSequenceHistory() {}
virtual bool getDoc(int num, Rcl::Doc &doc, std::string *sh = 0);
@@ -56,9 +58,11 @@ class DocSequenceHistory : public DocSequence {
virtual std::string getDescription() {return m_description;}
void setDescription(const std::string& desc) {m_description = desc;}
protected:
virtual Rcl::Db *getDb();
virtual std::shared_ptr<Rcl::Db> getDb() {
return m_db;
}
private:
Rcl::Db *m_db;
std::shared_ptr<Rcl::Db> m_db;
RclDynConf *m_hist;
time_t m_prevtime{-1};
std::string m_description; // This is just an nls translated 'doc history'