mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-12 22:14:35 +00:00
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:
parent
d7eaaba900
commit
2ea039ba99
@ -210,6 +210,8 @@ public:
|
|||||||
// file, and then to construct the Buffer's bibinfo from that.
|
// file, and then to construct the Buffer's bibinfo from that.
|
||||||
/// A cache for bibliography info
|
/// A cache for bibliography info
|
||||||
mutable BiblioInfo bibinfo_;
|
mutable BiblioInfo bibinfo_;
|
||||||
|
/// whether the bibinfo cache is valid
|
||||||
|
bool bibinfoCacheValid_;
|
||||||
/// Cache of timestamps of .bib files
|
/// Cache of timestamps of .bib files
|
||||||
map<FileName, time_t> bibfileStatus_;
|
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),
|
: parent_buffer(0), lyx_clean(true), bak_clean(true), unnamed(false),
|
||||||
read_only(readonly_), filename(file), file_fully_loaded(false),
|
read_only(readonly_), filename(file), file_fully_loaded(false),
|
||||||
toc_backend(&parent), macro_lock(false), timestamp_(0),
|
toc_backend(&parent), macro_lock(false), timestamp_(0),
|
||||||
checksum_(0), wa_(0), undo_(parent)
|
checksum_(0), wa_(0), undo_(parent), bibinfoCacheValid_(false)
|
||||||
{
|
{
|
||||||
temppath = createBufferTmpDir();
|
temppath = createBufferTmpDir();
|
||||||
lyxvc.setBuffer(&parent);
|
lyxvc.setBuffer(&parent);
|
||||||
@ -1346,6 +1348,14 @@ void Buffer::updateBibfilesCache() const
|
|||||||
bibfiles.end());
|
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
|
BiblioInfo const & Buffer::localBibInfo() const
|
||||||
{
|
{
|
||||||
support::FileNameList const & bibfilesCache = getBibfilesCache();
|
if (d->bibinfoCacheValid_) {
|
||||||
// compare the cached timestamps with the actual ones.
|
support::FileNameList const & bibfilesCache = getBibfilesCache();
|
||||||
bool changed = false;
|
// compare the cached timestamps with the actual ones.
|
||||||
support::FileNameList::const_iterator ei = bibfilesCache.begin();
|
support::FileNameList::const_iterator ei = bibfilesCache.begin();
|
||||||
support::FileNameList::const_iterator en = bibfilesCache.end();
|
support::FileNameList::const_iterator en = bibfilesCache.end();
|
||||||
for (; ei != en; ++ ei) {
|
for (; ei != en; ++ ei) {
|
||||||
time_t lastw = ei->lastModified();
|
time_t lastw = ei->lastModified();
|
||||||
if (lastw != d->bibfileStatus_[*ei]) {
|
if (lastw != d->bibfileStatus_[*ei]) {
|
||||||
changed = true;
|
d->bibinfoCacheValid_ = false;
|
||||||
d->bibfileStatus_[*ei] = lastw;
|
d->bibfileStatus_[*ei] = lastw;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (changed) {
|
if (!d->bibinfoCacheValid_) {
|
||||||
|
d->bibinfo_.clear();
|
||||||
for (InsetIterator it = inset_iterator_begin(inset()); it; ++it)
|
for (InsetIterator it = inset_iterator_begin(inset()); it; ++it)
|
||||||
it->fillWithBibKeys(d->bibinfo_, it);
|
it->fillWithBibKeys(d->bibinfo_, it);
|
||||||
|
d->bibinfoCacheValid_ = true;
|
||||||
}
|
}
|
||||||
return d->bibinfo_;
|
return d->bibinfo_;
|
||||||
}
|
}
|
||||||
|
@ -306,6 +306,8 @@ public:
|
|||||||
/// Update the cache with all bibfiles in use (including bibfiles
|
/// Update the cache with all bibfiles in use (including bibfiles
|
||||||
/// of loaded child documents).
|
/// of loaded child documents).
|
||||||
void updateBibfilesCache() const;
|
void updateBibfilesCache() const;
|
||||||
|
///
|
||||||
|
void invalidateBibfilesCache();
|
||||||
/// Return the cache with all bibfiles in use (including bibfiles
|
/// Return the cache with all bibfiles in use (including bibfiles
|
||||||
/// of loaded child documents).
|
/// of loaded child documents).
|
||||||
support::FileNameList const & getBibfilesCache() const;
|
support::FileNameList const & getBibfilesCache() const;
|
||||||
|
@ -233,7 +233,7 @@ Inset * createInsetHelper(Buffer & buf, FuncRequest const & cmd)
|
|||||||
case BIBTEX_CODE: {
|
case BIBTEX_CODE: {
|
||||||
InsetCommandParams icp(code);
|
InsetCommandParams icp(code);
|
||||||
InsetCommand::string2params(name, to_utf8(cmd.argument()), icp);
|
InsetCommand::string2params(name, to_utf8(cmd.argument()), icp);
|
||||||
return new InsetBibtex(icp);
|
return new InsetBibtex(buf, icp);
|
||||||
}
|
}
|
||||||
|
|
||||||
case CITE_CODE: {
|
case CITE_CODE: {
|
||||||
@ -454,7 +454,7 @@ Inset * readInset(Lexer & lex, Buffer const & buf)
|
|||||||
inset.reset(new InsetBibitem(inscmd));
|
inset.reset(new InsetBibitem(inscmd));
|
||||||
break;
|
break;
|
||||||
case BIBTEX_CODE:
|
case BIBTEX_CODE:
|
||||||
inset.reset(new InsetBibtex(inscmd));
|
inset.reset(new InsetBibtex(buf, inscmd));
|
||||||
break;
|
break;
|
||||||
case CITE_CODE:
|
case CITE_CODE:
|
||||||
inset.reset(new InsetCitation(inscmd));
|
inset.reset(new InsetCitation(inscmd));
|
||||||
|
@ -49,9 +49,19 @@ namespace Alert = frontend::Alert;
|
|||||||
namespace os = support::os;
|
namespace os = support::os;
|
||||||
|
|
||||||
|
|
||||||
InsetBibtex::InsetBibtex(InsetCommandParams const & p)
|
InsetBibtex::InsetBibtex(Buffer const & buf, InsetCommandParams const & p)
|
||||||
: InsetCommand(p, "bibtex")
|
: InsetCommand(p, "bibtex")
|
||||||
{}
|
{
|
||||||
|
Inset::setBuffer(const_cast<Buffer &>(buf));
|
||||||
|
buffer_->invalidateBibfilesCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
InsetBibtex::~InsetBibtex()
|
||||||
|
{
|
||||||
|
if (buffer_)
|
||||||
|
buffer_->invalidateBibfilesCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ParamInfo const & InsetBibtex::findInfo(string const & /* cmdName */)
|
ParamInfo const & InsetBibtex::findInfo(string const & /* cmdName */)
|
||||||
|
@ -26,7 +26,9 @@ namespace lyx {
|
|||||||
class InsetBibtex : public InsetCommand {
|
class InsetBibtex : public InsetCommand {
|
||||||
public:
|
public:
|
||||||
///
|
///
|
||||||
InsetBibtex(InsetCommandParams const &);
|
InsetBibtex(Buffer const &, InsetCommandParams const &);
|
||||||
|
///
|
||||||
|
virtual ~InsetBibtex();
|
||||||
///
|
///
|
||||||
docstring screenLabel() const;
|
docstring screenLabel() const;
|
||||||
///
|
///
|
||||||
|
Loading…
Reference in New Issue
Block a user