aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-12-01 15:04:56 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-12-01 15:04:56 +0000
commit5cae20abb1c10a17ef41bade1190127510357b05 (patch)
tree1395f7636c44fb08bc140adfe1cd0ec889f90724
parentf4c2e1a3659356f45b4f2587d3e7c8afd01d6395 (diff)
downloadpaludis-5cae20abb1c10a17ef41bade1190127510357b05.tar.gz
paludis-5cae20abb1c10a17ef41bade1190127510357b05.tar.xz
Reduce repository workload for certain common code paths
-rw-r--r--paludis/package_database.cc6
-rw-r--r--paludis/repositories/fake/fake_repository_base.cc13
-rw-r--r--paludis/repositories/vdb/vdb_repository.cc74
3 files changed, 65 insertions, 28 deletions
diff --git a/paludis/package_database.cc b/paludis/package_database.cc
index 2f4c0b3..fe69936 100644
--- a/paludis/package_database.cc
+++ b/paludis/package_database.cc
@@ -218,12 +218,6 @@ PackageDatabase::_do_query(const PackageDepAtom & a, const InstallState installe
if ((installed_state == is_uninstalled_only) && r->installed_interface)
continue;
- if (! r->has_category_named(a.package().category))
- continue;
-
- if (! r->has_package_named(a.package()))
- continue;
-
VersionSpecCollection::ConstPointer versions(r->version_specs(a.package()));
VersionSpecCollection::Iterator v(versions->begin()), v_end(versions->end());
for ( ; v != v_end ; ++v)
diff --git a/paludis/repositories/fake/fake_repository_base.cc b/paludis/repositories/fake/fake_repository_base.cc
index a846062..5aa9037 100644
--- a/paludis/repositories/fake/fake_repository_base.cc
+++ b/paludis/repositories/fake/fake_repository_base.cc
@@ -112,9 +112,10 @@ FakeRepositoryBase::do_category_names() const
QualifiedPackageNameCollection::ConstPointer
FakeRepositoryBase::do_package_names(const CategoryNamePart & c) const
{
- if (! has_category_named(c))
- throw InternalError(PALUDIS_HERE, "no category named " + stringify(c));
QualifiedPackageNameCollection::Pointer result(new QualifiedPackageNameCollection::Concrete);
+ if (! has_category_named(c))
+ return result;
+
PackageNamePartCollection::Iterator p(_imp->package_names.find(c)->second->begin()),
p_end(_imp->package_names.find(c)->second->end());
for ( ; p != p_end ; ++p)
@@ -126,9 +127,9 @@ VersionSpecCollection::ConstPointer
FakeRepositoryBase::do_version_specs(const QualifiedPackageName & n) const
{
if (! has_category_named(n.category))
- throw InternalError(PALUDIS_HERE, "no category");
+ return VersionSpecCollection::Pointer(new VersionSpecCollection::Concrete);
if (! has_package_named(n))
- throw InternalError(PALUDIS_HERE, "no package");
+ return VersionSpecCollection::Pointer(new VersionSpecCollection::Concrete);
return _imp->versions.find(n)->second;
}
@@ -136,9 +137,9 @@ bool
FakeRepositoryBase::do_has_version(const QualifiedPackageName & q, const VersionSpec & v) const
{
if (! has_category_named(q.category))
- throw InternalError(PALUDIS_HERE, "no category");
+ return false;
if (! has_package_named(q))
- throw InternalError(PALUDIS_HERE, "no package");
+ return false;
return _imp->versions.find(q)->second->find(v) !=
_imp->versions.find(q)->second->end();
}
diff --git a/paludis/repositories/vdb/vdb_repository.cc b/paludis/repositories/vdb/vdb_repository.cc
index b653876..9fedb96 100644
--- a/paludis/repositories/vdb/vdb_repository.cc
+++ b/paludis/repositories/vdb/vdb_repository.cc
@@ -325,11 +325,15 @@ namespace paludis
/// Do we have entries loaded?
mutable bool entries_valid;
+ /// Do we have category entries loaded?
+ mutable MakeHashedSet<CategoryNamePart>::Type category_entries_valid;
+
/// Our entries, keep this sorted!
mutable std::vector<VDBEntry> entries;
/// Load entries.
void load_entries() const;
+ void load_entries_for(const CategoryNamePart &) const;
/// Load metadata for one entry.
void load_entry(std::vector<VDBEntry>::iterator) const;
@@ -373,27 +377,59 @@ namespace paludis
Context context("When loading VDBRepository entries from '" +
stringify(location) + "':");
+ Log::get_instance()->message(ll_debug, lc_context, "VDB load entries started");
+
entries.clear();
+ category_entries_valid.clear();
entries_valid = true;
try
{
for (DirIterator cat_i(location), cat_iend ; cat_i != cat_iend ; ++cat_i)
- {
- if (! cat_i->is_directory())
- continue;
+ load_entries_for(CategoryNamePart(cat_i->basename()));
- for (DirIterator pkg_i(*cat_i), pkg_iend ; pkg_i != pkg_iend ; ++pkg_i)
- {
- PackageDepAtom atom("=" + cat_i->basename() + "/" + pkg_i->basename());
- entries.push_back(VDBEntry(atom.package(), *atom.version_spec_ptr()));
- }
+ std::sort(entries.begin(), entries.end());
+ }
+ catch (...)
+ {
+ entries_valid = false;
+ throw;
+ }
+
+ Log::get_instance()->message(ll_debug, lc_context, "VDB load entries done");
+ }
+
+ void
+ Implementation<VDBRepository>::load_entries_for(const CategoryNamePart & cat) const
+ {
+ MakeHashedSet<CategoryNamePart>::Type::const_iterator i(category_entries_valid.find(cat));
+ if (i != category_entries_valid.end())
+ return;
+
+ Context context("When loading VDBRepository entries for '" + stringify(cat) + "' from '" +
+ stringify(location) + "':");
+
+ Log::get_instance()->message(ll_debug, lc_context, "VDB load entries for '" +
+ stringify(cat) + "' started");
+
+ try
+ {
+ category_entries_valid.insert(cat);
+
+ FSEntry dir(location / stringify(cat));
+ if (! dir.is_directory())
+ return;
+
+ for (DirIterator pkg_i(dir), pkg_iend ; pkg_i != pkg_iend ; ++pkg_i)
+ {
+ PackageDepAtom atom("=" + stringify(cat) + "/" + pkg_i->basename());
+ entries.push_back(VDBEntry(atom.package(), *atom.version_spec_ptr()));
}
std::sort(entries.begin(), entries.end());
}
catch (...)
{
- entries_valid = false;
+ category_entries_valid.erase(cat);
throw;
}
}
@@ -403,6 +439,7 @@ namespace paludis
{
entries_valid = false;
entries.clear();
+ category_entries_valid.clear();
}
void
@@ -509,7 +546,7 @@ VDBRepository::do_has_package_named(const QualifiedPackageName & q) const
"' in " + stringify(name()) + ":");
if (! _imp->entries_valid)
- _imp->load_entries();
+ _imp->load_entries_for(q.category);
std::pair<std::vector<VDBEntry>::const_iterator, std::vector<VDBEntry>::const_iterator>
r(std::equal_range(_imp->entries.begin(), _imp->entries.end(), q,
@@ -572,6 +609,9 @@ VDBRepository::do_version_specs(const QualifiedPackageName & n) const
Context context("When fetching versions of '" + stringify(n) + "' in "
+ stringify(name()) + ":");
+ if (! _imp->entries_valid)
+ _imp->load_entries_for(n.category);
+
VersionSpecCollection::Pointer result(new VersionSpecCollection::Concrete);
std::pair<std::vector<VDBEntry>::const_iterator, std::vector<VDBEntry>::const_iterator>
@@ -603,7 +643,7 @@ VDBRepository::do_version_metadata(
"-" + stringify(v) + "':");
if (! _imp->entries_valid)
- _imp->load_entries();
+ _imp->load_entries_for(q.category);
std::pair<std::vector<VDBEntry>::iterator, std::vector<VDBEntry>::iterator>
r(std::equal_range(_imp->entries.begin(), _imp->entries.end(), std::make_pair(
@@ -712,7 +752,7 @@ VDBRepository::do_installed_time(const QualifiedPackageName & q,
"-" + stringify(v) + "':");
if (! _imp->entries_valid)
- _imp->load_entries();
+ _imp->load_entries_for(q.category);
std::pair<std::vector<VDBEntry>::iterator, std::vector<VDBEntry>::iterator>
r(std::equal_range(_imp->entries.begin(), _imp->entries.end(), std::make_pair(
@@ -746,11 +786,10 @@ UseFlagState
VDBRepository::do_query_use(const UseFlagName & f,
const PackageDatabaseEntry * const e) const
{
- if (! _imp->entries_valid)
- _imp->load_entries();
-
- if (e->repository == name())
+ if (e && e->repository == name())
{
+ if (! _imp->entries_valid)
+ _imp->load_entries_for(e->name.category);
std::pair<std::vector<VDBEntry>::iterator, std::vector<VDBEntry>::iterator>
r(std::equal_range(_imp->entries.begin(), _imp->entries.end(), std::make_pair(
@@ -1416,6 +1455,9 @@ VDBRepository::do_category_names_containing_package(const PackageNamePart & p) c
if (_imp->name_cache_map.end() == r)
{
+ Log::get_instance()->message(ll_debug, lc_context, "Loading names cache for '" +
+ stringify(p) + "'");
+
r = _imp->name_cache_map.insert(std::make_pair(p, std::list<CategoryNamePart>())).first;
FSEntry ff(_imp->names_cache / stringify(p));