Fix some of the BibTeX cache issues. We need to be able to invalidate the cache when

InsetBibtex's get created and destroyed, or modified.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@25136 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Richard Heck 2008-06-05 06:42:53 +00:00
parent d7eaaba900
commit 2ea039ba99
5 changed files with 45 additions and 18 deletions

View File

@ -210,6 +210,8 @@ public:
// file, and then to construct the Buffer's bibinfo from that.
/// A cache for bibliography info
mutable BiblioInfo bibinfo_;
/// whether the bibinfo cache is valid
bool bibinfoCacheValid_;
/// Cache of timestamps of .bib files
map<FileName, time_t> bibfileStatus_;
@ -243,7 +245,7 @@ Buffer::Impl::Impl(Buffer & parent, FileName const & file, bool readonly_)
: parent_buffer(0), lyx_clean(true), bak_clean(true), unnamed(false),
read_only(readonly_), filename(file), file_fully_loaded(false),
toc_backend(&parent), macro_lock(false), timestamp_(0),
checksum_(0), wa_(0), undo_(parent)
checksum_(0), wa_(0), undo_(parent), bibinfoCacheValid_(false)
{
temppath = createBufferTmpDir();
lyxvc.setBuffer(&parent);
@ -1346,6 +1348,14 @@ void Buffer::updateBibfilesCache() const
bibfiles.end());
}
}
// the bibinfo cache is now invalid
d->bibinfoCacheValid_ = false;
}
void Buffer::invalidateBibfilesCache()
{
d->bibinfoCacheValid_ = false;
}
@ -1377,23 +1387,26 @@ BiblioInfo const & Buffer::masterBibInfo() const
BiblioInfo const & Buffer::localBibInfo() const
{
support::FileNameList const & bibfilesCache = getBibfilesCache();
// compare the cached timestamps with the actual ones.
bool changed = false;
support::FileNameList::const_iterator ei = bibfilesCache.begin();
support::FileNameList::const_iterator en = bibfilesCache.end();
for (; ei != en; ++ ei) {
time_t lastw = ei->lastModified();
if (lastw != d->bibfileStatus_[*ei]) {
changed = true;
d->bibfileStatus_[*ei] = lastw;
break;
if (d->bibinfoCacheValid_) {
support::FileNameList const & bibfilesCache = getBibfilesCache();
// compare the cached timestamps with the actual ones.
support::FileNameList::const_iterator ei = bibfilesCache.begin();
support::FileNameList::const_iterator en = bibfilesCache.end();
for (; ei != en; ++ ei) {
time_t lastw = ei->lastModified();
if (lastw != d->bibfileStatus_[*ei]) {
d->bibinfoCacheValid_ = false;
d->bibfileStatus_[*ei] = lastw;
break;
}
}
}
if (changed) {
if (!d->bibinfoCacheValid_) {
d->bibinfo_.clear();
for (InsetIterator it = inset_iterator_begin(inset()); it; ++it)
it->fillWithBibKeys(d->bibinfo_, it);
d->bibinfoCacheValid_ = true;
}
return d->bibinfo_;
}

View File

@ -306,6 +306,8 @@ public:
/// Update the cache with all bibfiles in use (including bibfiles
/// of loaded child documents).
void updateBibfilesCache() const;
///
void invalidateBibfilesCache();
/// Return the cache with all bibfiles in use (including bibfiles
/// of loaded child documents).
support::FileNameList const & getBibfilesCache() const;

View File

@ -233,7 +233,7 @@ Inset * createInsetHelper(Buffer & buf, FuncRequest const & cmd)
case BIBTEX_CODE: {
InsetCommandParams icp(code);
InsetCommand::string2params(name, to_utf8(cmd.argument()), icp);
return new InsetBibtex(icp);
return new InsetBibtex(buf, icp);
}
case CITE_CODE: {
@ -454,7 +454,7 @@ Inset * readInset(Lexer & lex, Buffer const & buf)
inset.reset(new InsetBibitem(inscmd));
break;
case BIBTEX_CODE:
inset.reset(new InsetBibtex(inscmd));
inset.reset(new InsetBibtex(buf, inscmd));
break;
case CITE_CODE:
inset.reset(new InsetCitation(inscmd));

View File

@ -49,9 +49,19 @@ namespace Alert = frontend::Alert;
namespace os = support::os;
InsetBibtex::InsetBibtex(InsetCommandParams const & p)
InsetBibtex::InsetBibtex(Buffer const & buf, InsetCommandParams const & p)
: InsetCommand(p, "bibtex")
{}
{
Inset::setBuffer(const_cast<Buffer &>(buf));
buffer_->invalidateBibfilesCache();
}
InsetBibtex::~InsetBibtex()
{
if (buffer_)
buffer_->invalidateBibfilesCache();
}
ParamInfo const & InsetBibtex::findInfo(string const & /* cmdName */)

View File

@ -26,7 +26,9 @@ namespace lyx {
class InsetBibtex : public InsetCommand {
public:
///
InsetBibtex(InsetCommandParams const &);
InsetBibtex(Buffer const &, InsetCommandParams const &);
///
virtual ~InsetBibtex();
///
docstring screenLabel() const;
///