--- a/src/query/docseqhist.cpp
+++ b/src/query/docseqhist.cpp
@@ -14,15 +14,15 @@
* Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
+#include "docseqhist.h"
+
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <cmath>
-#include <list>
-using std::list;
+using std::vector;
-#include "docseqhist.h"
#include "rcldb.h"
#include "fileudi.h"
#include "base64.h"
@@ -77,7 +77,7 @@
// Old style entry found, make an udi, using the fs udi maker
make_udi(fn, ipath, udi);
}
- LOGDEB1("RclDHistoryEntry::decode: udi [" << (udi) << "]\n" );
+ LOGDEB1("RclDHistoryEntry::decode: udi [" << udi << "]\n");
return true;
}
@@ -89,54 +89,46 @@
bool historyEnterDoc(RclDynConf *dncf, const string& udi)
{
- LOGDEB1("historyEnterDoc: [" << (udi) << "] into " << (dncf->getFilename()) << "\n" );
+ LOGDEB1("historyEnterDoc: [" << udi << "] into " << dncf->getFilename() <<
+ "\n");
RclDHistoryEntry ne(time(0), udi);
RclDHistoryEntry scratch;
return dncf->insertNew(docHistSubKey, ne, scratch, 200);
}
-list<RclDHistoryEntry> getDocHistory(RclDynConf* dncf)
+vector<RclDHistoryEntry> getDocHistory(RclDynConf* dncf)
{
- return dncf->getList<RclDHistoryEntry>(docHistSubKey);
+ return dncf->getEntries<std::vector, RclDHistoryEntry>(docHistSubKey);
}
-
bool DocSequenceHistory::getDoc(int num, Rcl::Doc &doc, string *sh)
{
// Retrieve history list
if (!m_hist)
return false;
- if (m_hlist.empty())
- m_hlist = getDocHistory(m_hist);
+ if (m_history.empty())
+ m_history = getDocHistory(m_hist);
- if (num < 0 || num >= (int)m_hlist.size())
+ if (num < 0 || num >= (int)m_history.size())
return false;
- int skip;
- if (m_prevnum >= 0 && num >= m_prevnum) {
- skip = num - m_prevnum;
- } else {
- skip = num;
- m_it = m_hlist.begin();
- m_prevtime = -1;
- }
- m_prevnum = num;
- while (skip--)
- m_it++;
+ // We get the history oldest first, but our users expect newest first
+ RclDHistoryEntry& hentry = m_history[m_history.size() - 1 - num];
if (sh) {
if (m_prevtime < 0 ||
- abs (float(m_prevtime) - float(m_it->unixtime)) > 86400) {
- m_prevtime = m_it->unixtime;
- time_t t = (time_t)(m_it->unixtime);
+ abs (float(m_prevtime) - float(hentry.unixtime)) > 86400) {
+ m_prevtime = hentry.unixtime;
+ time_t t = (time_t)(hentry.unixtime);
*sh = string(ctime(&t));
// Get rid of the final \n in ctime
sh->erase(sh->length()-1);
- } else
+ } else {
sh->erase();
+ }
}
// For now history does not store an index id. Use empty doc as ref.
Rcl::Doc idxdoc;
- bool ret = m_db->getDoc(m_it->udi, idxdoc, doc);
+ bool ret = m_db->getDoc(hentry.udi, idxdoc, doc);
if (!ret || doc.pc == -1) {
doc.url = "UNKNOWN";
doc.ipath = "";
@@ -156,8 +148,8 @@
int DocSequenceHistory::getResCnt()
{
- if (m_hlist.empty())
- m_hlist = getDocHistory(m_hist);
- return int(m_hlist.size());
+ if (m_history.empty())
+ m_history = getDocHistory(m_hist);
+ return int(m_history.size());
}