Author: dmacvicar Date: Wed Aug 1 15:15:43 2007 New Revision: 6363 URL: http://svn.opensuse.org/viewcvs/zypp?rev=6363&view=rev Log: - implement disk usage basic infrastructure for cache store - todo: retrieving it - make changelog and filelist api similar to the other functions Modified: trunk/libzypp/zypp/cache/CacheInitializer.h trunk/libzypp/zypp/cache/CacheStore.cc trunk/libzypp/zypp/cache/CacheStore.h trunk/libzypp/zypp/cache/schema/schema.sql trunk/libzypp/zypp/data/ResolvableDataConsumer.h trunk/libzypp/zypp/parser/yum/RepoParser.cc Modified: trunk/libzypp/zypp/cache/CacheInitializer.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/cache/CacheInitializ... ============================================================================== --- trunk/libzypp/zypp/cache/CacheInitializer.h (original) +++ trunk/libzypp/zypp/cache/CacheInitializer.h Wed Aug 1 15:15:43 2007 @@ -19,7 +19,7 @@ #include "zypp/Pathname.h" #include "zypp/cache/sqlite3x/sqlite3x.hpp" -#define ZYPP_CACHE_SCHEMA_VERSION 1000 +#define ZYPP_CACHE_SCHEMA_VERSION 1001 /////////////////////////////////////////////////////////////////// namespace zypp Modified: trunk/libzypp/zypp/cache/CacheStore.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/cache/CacheStore.cc?... ============================================================================== --- trunk/libzypp/zypp/cache/CacheStore.cc (original) +++ trunk/libzypp/zypp/cache/CacheStore.cc Wed Aug 1 15:15:43 2007 @@ -128,7 +128,11 @@ "insert into patch_packages_baseversions (patch_package_id, version, release, epoch) " "values (:patch_package_id, :version, :release, :epoch)" )); - + update_disk_usage_cmd.reset( new sqlite3_command (con, + "insert or replace into resolvable_disk_usage (resolvable_id, dir_name_id, files, size) " + "values (:resolvable_id, :dir_name_id, :files, :size)" )); + + // disable autocommit con.executenonquery("BEGIN;"); } @@ -190,6 +194,8 @@ sqlite3_command_ptr insert_deltarpm_cmd; sqlite3_command_ptr append_patch_baseversion_cmd; + sqlite3_command_ptr update_disk_usage_cmd; + map<string, RecordId> name_cache; map< pair<string,string>, RecordId> type_cache; int name_cache_hits; @@ -412,8 +418,7 @@ return id; } -RecordId CacheStore::consumeChangelog( const data::RecordId & repository_id, - const data::Resolvable_Ptr & resolvable, +RecordId CacheStore::consumeChangelog( const data::RecordId &resolvable_id, const Changelog & changelog ) { //! \todo maybe appendChangelog(const data::RecordId & resolvable_id, Changelog changelog) will be needed @@ -422,14 +427,37 @@ return data::noRecordId; } -RecordId CacheStore::consumeFilelist( const data::RecordId & repository_id, - const data::Resolvable_Ptr & resolvable, +RecordId CacheStore::consumeFilelist( const data::RecordId &resolvable_id, const data::Filenames & filenames ) { //! \todo maybe consumeFilelist(const data::RecordId & resolvable_id, data::Filenames &) will be needed return data::noRecordId; } +void CacheStore::consumeDiskUsage( const data::RecordId &resolvable_id, + const DiskUsage &disk ) +{ + // iterate over entries + for ( DiskUsage::const_iterator it = disk.begin(); + it != disk.end(); + ++it ) + { + data::RecordId dirid = lookupOrAppendDirName( (*it).path ); + try + { + _pimpl->update_disk_usage_cmd->bind(":resolvable_id", resolvable_id); + _pimpl->update_disk_usage_cmd->bind(":dir_name_id", dirid); + _pimpl->update_disk_usage_cmd->bind(":files", (int)(*it)._files ); + _pimpl->update_disk_usage_cmd->bind(":size", (int)(*it)._size ); + _pimpl->update_disk_usage_cmd->executenonquery(); + } + catch ( const sqlite3x::database_error &e ) + { + ZYPP_RETHROW(e); + } + } +} + void CacheStore::updatePackageLang( const data::RecordId & resolvable_id, const data::Packagebase_Ptr & data_r ) { Modified: trunk/libzypp/zypp/cache/CacheStore.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/cache/CacheStore.h?r... ============================================================================== --- trunk/libzypp/zypp/cache/CacheStore.h (original) +++ trunk/libzypp/zypp/cache/CacheStore.h Wed Aug 1 15:15:43 2007 @@ -169,8 +169,7 @@ * \param changelog the changelog * \todo see implementation */ - virtual data::RecordId consumeChangelog( const data::RecordId & repository_id, - const data::Resolvable_Ptr & resolvable, + virtual data::RecordId consumeChangelog( const data::RecordId & resolvable_id, const Changelog & changelog ); /** @@ -182,9 +181,24 @@ * \param filenames list of filenames the resolvable contains * \todo see implementation */ - virtual data::RecordId consumeFilelist( const data::RecordId &repository_id, - const data::Resolvable_Ptr & resolvable, + virtual data::RecordId consumeFilelist( const data::RecordId & resolvable_id, const data::Filenames & filenames ); + + /** + * Implementation of the \ref ResolvableDataConsumer interface + * + * Consume disk usage of a resolvable, inserting it in the cache. + * + * Repeated entries are updated (replaced) + * + * \param repository_id ownership. + * \param resolvable resolvable for which the filelist is to be saved + * \param disk Disk usage object + * \todo see implementation + */ + virtual void consumeDiskUsage( const data::RecordId &resolvable_id, + const DiskUsage &disk ); + /** * Implementation of the \ref ResolvableDataConsumer interface Modified: trunk/libzypp/zypp/cache/schema/schema.sql URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/cache/schema/schema.... ============================================================================== --- trunk/libzypp/zypp/cache/schema/schema.sql (original) +++ trunk/libzypp/zypp/cache/schema/schema.sql Wed Aug 1 15:15:43 2007 @@ -258,7 +258,34 @@ ); CREATE INDEX split_capabilities_resolvable ON split_capabilities(resolvable_id); --- Auto clean capabilities +------------------------------------------------ +-- File list +------------------------------------------------ + +CREATE TABLE resolvable_files ( + resolvable_id INTEGER REFERENCES resolvables (id) + , file_id INTEGER REFERENCES files (id) + , PRIMARY KEY ( resolvable_id, file_id ) +); + +------------------------------------------------ +-- Disk usage +------------------------------------------------ + +CREATE TABLE resolvable_disk_usage ( + resolvable_id INTEGER REFERENCES resolvables (id) + , dir_name_id INTEGER REFERENCES dir_name (id) + , files INTEGER + , size INTEGER + , PRIMARY KEY ( resolvable_id, dir_name_id ) +); +CREATE INDEX disk_usage_resolvable_id ON resolvable_disk_usage(resolvable_id); +CREATE INDEX disk_usage_dir_name_id ON resolvable_disk_usage(dir_name_id); + +------------------------------------------------ +-- Cleanup +------------------------------------------------ + CREATE TRIGGER remove_resolvables AFTER DELETE ON resolvables BEGIN @@ -271,8 +298,13 @@ DELETE FROM text_attributes WHERE weak_resolvable_id = old.id; DELETE FROM numeric_attributes WHERE weak_resolvable_id = old.id; + DELETE FROM resolvable_disk_usage WHERE resolvable_id = old.id; + DELETE FROM resolvable_files WHERE resolvable_id = old.id; END; + + + ------------------------------------------------ -- Associate resolvables and repositories ------------------------------------------------ Modified: trunk/libzypp/zypp/data/ResolvableDataConsumer.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/data/ResolvableDataC... ============================================================================== --- trunk/libzypp/zypp/data/ResolvableDataConsumer.h (original) +++ trunk/libzypp/zypp/data/ResolvableDataConsumer.h Wed Aug 1 15:15:43 2007 @@ -11,6 +11,7 @@ #define ZYPP_ResolvableDataConsumer_H +#include "zypp/DiskUsage.h" #include "zypp/data/RecordId.h" #include "zypp/data/ResolvableData.h" @@ -37,10 +38,12 @@ virtual data::RecordId consumeScript ( const data::RecordId & repository_id, const data::Script_Ptr & ) = 0; virtual data::RecordId consumePattern ( const data::RecordId & repository_id, const data::Pattern_Ptr & ) = 0; - virtual data::RecordId consumeChangelog ( const data::RecordId & repository_id, const data::Resolvable_Ptr &, const Changelog & ) = 0; - virtual data::RecordId consumeFilelist ( const data::RecordId & repository_id, const data::Resolvable_Ptr &, const data::Filenames & ) = 0; - + virtual data::RecordId consumeChangelog ( const data::RecordId & resolvable_id, const Changelog & ) = 0; + virtual data::RecordId consumeFilelist ( const data::RecordId & resolvable_id, const data::Filenames & ) = 0; + virtual void consumeDiskUsage ( const data::RecordId &resolvable_id, const DiskUsage &disk ) = 0; + virtual void updatePackageLang( const data::RecordId & resolvable_id, const data::Packagebase_Ptr & data_r ) = 0; + }; } // namespace parser Modified: trunk/libzypp/zypp/parser/yum/RepoParser.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/parser/yum/RepoParse... ============================================================================== --- trunk/libzypp/zypp/parser/yum/RepoParser.cc (original) +++ trunk/libzypp/zypp/parser/yum/RepoParser.cc Wed Aug 1 15:15:43 2007 @@ -246,7 +246,7 @@ bool RepoParser::Impl::other_CB( const data::Resolvable_Ptr & res_ptr, const Changelog & changelog) { - _consumer.consumeChangelog(_repository_id, res_ptr, changelog); + //_consumer.consumeChangelog(_repository_id, res_ptr, changelog); /* DBG << "got changelog for " << res_ptr->name << res_ptr->edition << " " @@ -263,7 +263,7 @@ bool RepoParser::Impl::filelist_CB( const data::Resolvable_Ptr & res_ptr, const data::Filenames & filenames) { - _consumer.consumeFilelist(_repository_id, res_ptr, filenames); + //_consumer.consumeFilelist(_repository_id, res_ptr, filenames); /* DBG << "got filelist for " << res_ptr->name << res_ptr->edition << " " -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org