Use one transaction when updating packages via `PackageUpdater`

This should likely be done in the other updating functions of the
`Database` class as well to avoid indexes and actual data appearing
inconsistent during the write operations.
This commit is contained in:
Martchus 2022-11-01 15:11:49 +01:00
parent c6a8c81784
commit 84ef92aaa2
1 changed files with 6 additions and 9 deletions

View File

@ -906,6 +906,7 @@ void PackageUpdater::commit()
{
const auto &storage = m_database.m_storage;
auto &pkgTxn = m_d->packagesTxn;
auto txnHandle = pkgTxn.getTransactionHandle();
if (m_d->clear) {
const auto &toPreserve = m_d->handledIds;
for (auto i = pkgTxn.begin<std::unique_ptr>(); i != pkgTxn.end(); ++i) {
@ -914,47 +915,43 @@ void PackageUpdater::commit()
}
}
}
pkgTxn.commit();
{
auto txn = storage->providedDeps.getRWTransaction();
auto txn = storage->providedDeps.getRWTransaction(txnHandle);
if (m_d->clear) {
txn.clear();
}
for (auto &[dependencyName, affected] : m_d->affectedProvidedDeps) {
m_d->submit(dependencyName, affected, txn);
}
txn.commit();
}
{
auto txn = storage->requiredDeps.getRWTransaction();
auto txn = storage->requiredDeps.getRWTransaction(txnHandle);
if (m_d->clear) {
txn.clear();
}
for (auto &[dependencyName, affected] : m_d->affectedRequiredDeps) {
m_d->submit(dependencyName, affected, txn);
}
txn.commit();
}
{
auto txn = storage->providedLibs.getRWTransaction();
auto txn = storage->providedLibs.getRWTransaction(txnHandle);
if (m_d->clear) {
txn.clear();
}
for (auto &[libraryName, affected] : m_d->affectedProvidedLibs) {
m_d->submit(libraryName, affected, txn);
}
txn.commit();
}
{
auto txn = storage->requiredLibs.getRWTransaction();
auto txn = storage->requiredLibs.getRWTransaction(txnHandle);
if (m_d->clear) {
txn.clear();
}
for (auto &[libraryName, affected] : m_d->affectedRequiredLibs) {
m_d->submit(libraryName, affected, txn);
}
txn.commit();
}
pkgTxn.commit();
m_d->lock.unlock();
}