diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2010-02-18T13·40+0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2010-02-18T13·40+0000 |
commit | dbddac0fe91072b402ccb3801c952e3159f0cba4 (patch) | |
tree | 4c94160c57aa8a3041e9af9b8eed6137734af1c9 /src/libstore/local-store.cc | |
parent | c1a07f94451cfa93aa9ac986188d0e9a536e4b9f (diff) |
* Assign an integer id to every row in the ValidPaths table in order
to make the Refs table more space-efficient. For instance, this reduces the size of the database on my laptop from 93 MiB to 18 MiB. (It was 72 MiB with the old schema on an ext3 disk with a 1 KiB block size.)
Diffstat (limited to 'src/libstore/local-store.cc')
-rw-r--r-- | src/libstore/local-store.cc | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index 55637dd85903..03c5d76b377e 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -1229,6 +1229,8 @@ void LocalStore::upgradeStore6() if (sqlite3_exec(db, "begin;", 0, 0, 0) != SQLITE_OK) throw SQLiteError(db, "running `begin' command"); + + std::map<Path, sqlite3_int64> pathToId; foreach (PathSet::iterator, i, validPaths) { ValidPathInfo info = queryPathInfo(*i, true); @@ -1245,12 +1247,24 @@ void LocalStore::upgradeStore6() if (sqlite3_step(registerStmt) != SQLITE_DONE) throw SQLiteError(db, "registering valid path in database"); + pathToId[*i] = sqlite3_last_insert_rowid(db); + + std::cerr << "."; + } + + std::cerr << "|"; + + foreach (PathSet::iterator, i, validPaths) { + ValidPathInfo info = queryPathInfo(*i, true); + foreach (PathSet::iterator, j, info.references) { if (sqlite3_reset(addRefStmt) != SQLITE_OK) throw SQLiteError(db, "resetting statement"); - if (sqlite3_bind_text(addRefStmt, 1, i->c_str(), -1, SQLITE_TRANSIENT) != SQLITE_OK) + if (sqlite3_bind_int(addRefStmt, 1, pathToId[*i]) != SQLITE_OK) throw SQLiteError(db, "binding argument 1"); - if (sqlite3_bind_text(addRefStmt, 2, j->c_str(), -1, SQLITE_TRANSIENT) != SQLITE_OK) + if (pathToId.find(*j) == pathToId.end()) + throw Error(format("path `%1%' referenced by `%2%' is invalid") % *j % *i); + if (sqlite3_bind_int(addRefStmt, 2, pathToId[*j]) != SQLITE_OK) throw SQLiteError(db, "binding argument 2"); if (sqlite3_step(addRefStmt) != SQLITE_DONE) throw SQLiteError(db, "adding reference to database"); |