On 08/09/2010 01:48 PM, Jean-Marc Lasgouttes wrote:
Le 9 août 10 à 19:01, rgh...@lyx.org a écrit :
Log:
More work toward speeding up the bibfile caching stuff.
This looks good.
From bug 6846:
====
So I've had a look at this and made some more changes. But I've got two
concerns about doing things via updateBuffer().
We need to call all of this from GuiCitation?
<http://www.lyx.org/trac/wiki/GuiCitation>. I.e., suppose LyX has been
sitting around idea for a while and now the user hits Insert>Citation.
Then we want to check if the BibTeX files have changed and, if so,
update our list of citations. So then we would have to call
updateBuffer() from GuiCitation?
<http://www.lyx.org/trac/wiki/GuiCitation>, where we now call
checkBibinfoCache(). Is that going to be OK?
The same goes for Buffer::changeRefsIfUnique(). Here, we need to make
sure the cache of keys is up to date and, if not, we have to reload it.
Can I call updateBuffer() from there?
Thoughts?
I'll attach a partial patch so you can see how this would go.
====
rh
Index: src/Buffer.cpp
===================================================================
--- src/Buffer.cpp (revision 35105)
+++ src/Buffer.cpp (working copy)
@@ -1749,6 +1749,13 @@
d->bibfile_cache_valid_ = false;
}
+
+bool Buffer::isBibinfoCacheValid() const
+{
+ return d->bibinfo_cache_valid_;
+}
+
+
support::FileNameList const & Buffer::getBibfilesCache(UpdateScope scope) const
{
// If this is a child document, use the parent's cache instead.
@@ -1795,15 +1802,6 @@
d->bibfile_status_[*ei] = lastw;
}
}
-
- // FIXME Don't do this here, but instead gather them as we go through
- // updateBuffer().
- if (!d->bibinfo_cache_valid_) {
- d->bibinfo_.clear();
- for (InsetIterator it = inset_iterator_begin(inset()); it; ++it)
- it->fillWithBibKeys(d->bibinfo_, it);
- d->bibinfo_cache_valid_ = true;
- }
}
@@ -2962,6 +2960,7 @@
vector<docstring> labels;
string paramName;
checkBibInfoCache();
+ updateBuffer();
BiblioInfo const & keys = masterBibInfo();
BiblioInfo::const_iterator bit = keys.begin();
BiblioInfo::const_iterator bend = keys.end();
@@ -3752,6 +3751,7 @@
cbuf.tocBackend().update();
if (scope == UpdateMaster)
cbuf.structureChanged();
+ d->bibinfo_cache_valid_ = true;
}
Index: src/Buffer.h
===================================================================
--- src/Buffer.h (revision 35105)
+++ src/Buffer.h (working copy)
@@ -349,6 +349,8 @@
void invalidateBibinfoCache();
/// This invalidates the cache of files we need to check.
void invalidateBibfileCache();
+ ///
+ bool isBibinfoCacheValid() const;
/// Updates the cached bibliography information.
/// Note that you MUST call this method to update the cache. It will
/// not happen otherwise. (Currently, it is called at the start of
Index: src/frontends/qt4/GuiCitation.cpp
===================================================================
--- src/frontends/qt4/GuiCitation.cpp (revision 35105)
+++ src/frontends/qt4/GuiCitation.cpp (working copy)
@@ -756,6 +756,8 @@
BiblioInfo const & GuiCitation::bibInfo() const
{
buffer().checkBibInfoCache();
+ if (buffer().isBibinfoCacheValid())
+ buffer().updateMacros();
return buffer().masterBibInfo();
}
Index: src/insets/InsetBibitem.cpp
===================================================================
--- src/insets/InsetBibitem.cpp (revision 35105)
+++ src/insets/InsetBibitem.cpp (working copy)
@@ -283,6 +283,9 @@
} else {
autolabel_ = from_ascii("??");
}
+ if (!buffer().isBibinfoCacheValid())
+ // FIXME
+ return;
}
Index: src/insets/InsetBibtex.cpp
===================================================================
--- src/insets/InsetBibtex.cpp (revision 35105)
+++ src/insets/InsetBibtex.cpp (working copy)
@@ -661,6 +661,14 @@
}
+void InsetBibtex::updateBuffer(ParIterator const &, UpdateType)
+{
+ if (buffer().isBibinfoCacheValid())
+ return;
+ // FIXME fillWithBibKeys(...);
+}
+
+
// This method returns a comma separated list of Bibtex entries
void InsetBibtex::fillWithBibKeys(BiblioInfo & keylist,
InsetIterator const & /*di*/) const
Index: src/insets/InsetBibtex.h
===================================================================
--- src/insets/InsetBibtex.h (revision 35105)
+++ src/insets/InsetBibtex.h (working copy)
@@ -41,9 +41,9 @@
DisplayType display() const { return AlignCenter; }
///
int latex(odocstream &, OutputParams const &) const;
+ ///
+ void updateBuffer(ParIterator const &, UpdateType);
///
- void fillWithBibKeys(BiblioInfo &, InsetIterator const &) const;
- ///
support::FileNameList getBibFiles() const;
///
bool addDatabase(docstring const &);
@@ -74,6 +74,8 @@
///
void editDatabases() const;
///
+ void fillWithBibKeys(BiblioInfo &, InsetIterator const &) const;
+ ///
Inset * clone() const { return new InsetBibtex(*this); }
};
Index: src/insets/Inset.h
===================================================================
--- src/insets/Inset.h (revision 35105)
+++ src/insets/Inset.h (working copy)
@@ -477,8 +477,6 @@
/// Add an entry to the TocList
/// pit is the ParConstIterator of the paragraph containing the inset
virtual void addToToc(DocIterator const &) {}
- /// Fill keys with BibTeX information
- virtual void fillWithBibKeys(BiblioInfo &, InsetIterator const &) const {}
/// Update the counters of this inset and of its contents.
/// The boolean indicates whether we are preparing for output, e.g.,
/// of XHTML.
Index: src/insets/InsetInclude.cpp
===================================================================
--- src/insets/InsetInclude.cpp (revision 35105)
+++ src/insets/InsetInclude.cpp (working copy)
@@ -830,18 +830,6 @@
}
-void InsetInclude::fillWithBibKeys(BiblioInfo & keys,
- InsetIterator const & /*di*/) const
-{
- if (loadIfNeeded()) {
- string const included_file = includedFileName(buffer(), params()).absFileName();
- Buffer * tmp = theBufferList().getBuffer(FileName(included_file));
- BiblioInfo const & newkeys = tmp->localBibInfo();
- keys.mergeBiblioInfo(newkeys);
- }
-}
-
-
void InsetInclude::metrics(MetricsInfo & mi, Dimension & dim) const
{
LASSERT(mi.base.bv, /**/);
Index: src/insets/InsetInclude.h
===================================================================
--- src/insets/InsetInclude.h (revision 35105)
+++ src/insets/InsetInclude.h (working copy)
@@ -54,13 +54,6 @@
///
void setChildBuffer(Buffer * buffer);
- /** Fills \c keys
- * \param buffer the Buffer containing this inset.
- * \param keys the list of bibkeys in the child buffer.
- * \param it not used here
- */
- void fillWithBibKeys(BiblioInfo & keys, InsetIterator const & it) const;
-
///
bool hasSettings() const { return true; }
///