清理旧数据操作无效问题修复

This commit is contained in:
shell committed 2026-07-30 03:40:01 +08:00
1 parent f0b6efb126
commit ae3a25857f
2 files changed
+20 -13

No files matched your search

+1 -1
View File
@@ -89,7 +89,7 @@ namespace seafile::fs
tl::expected<void, api::SeafileException> fetchAndStoreRepoDir( tl::expected<void, api::SeafileException> fetchAndStoreRepoDir(
const std::string& repo_id, const std::string& parent_path); const std::string& repo_id, const std::string& parent_path);
std::vector<storage::RepoEntry> queryDirectChildren( std::vector<storage::RepoEntry> queryDirectoryChildren(
const std::string& repo_id, const std::string& parent_path); const std::string& repo_id, const std::string& parent_path);
struct Database; struct Database;
+19 -12
View File
@@ -194,19 +194,26 @@ namespace seafile::fs {
tl::expected<void, api::SeafileException> SeafileStore::checkAndSync(const std::string &repo_id) { tl::expected<void, api::SeafileException> SeafileStore::checkAndSync(const std::string &repo_id) {
if (!this->checkIsUpdated(repo_id)) { if (!this->checkIsUpdated(repo_id)) {
std::lock_guard lock(database->mutex);
auto &storage = this->database->storage;
try { try {
storage.remove<RepoEntry>(sqlite_orm::where( {
sqlite_orm::c(&RepoEntry::repo_id) == repo_id std::lock_guard lock(database->mutex);
) auto &storage = this->database->storage;
); storage.remove_all<RepoEntry>(sqlite_orm::where(
sqlite_orm::c(&RepoEntry::repo_id) == repo_id
)
);
}
const auto repo_entries = this->api.repoDir(repo_id, "/"); const auto repo_entries = this->api.repoDir(repo_id, "/");
if (!repo_entries) { if (!repo_entries) {
return tl::make_unexpected(repo_entries.error()); return tl::make_unexpected(repo_entries.error());
} }
for (const auto &repo_entry: *repo_entries) { {
storage.replace(RepoEntry::from_api_model(repo_id, "/", repo_entry)); std::lock_guard lock(database->mutex);
auto &storage = this->database->storage;
for (const auto &repo_entry: *repo_entries) {
storage.replace(RepoEntry::from_api_model(repo_id, "/", repo_entry));
}
} }
} catch (std::exception &e) { } catch (std::exception &e) {
return tl::make_unexpected(api::SeafileException(e.what())); return tl::make_unexpected(api::SeafileException(e.what()));
@@ -258,7 +265,7 @@ namespace seafile::fs {
existing = existings.at(0); existing = existings.at(0);
} }
if (existing && existing->head_commit_id != storage_repo.head_commit_id) { if (existing && existing->head_commit_id != storage_repo.head_commit_id) {
storage.remove<RepoEntry>(sqlite_orm::where( storage.remove_all<RepoEntry>(sqlite_orm::where(
sqlite_orm::c(&RepoEntry::repo_id) == storage_repo.id)); sqlite_orm::c(&RepoEntry::repo_id) == storage_repo.id));
} }
storage.replace(storage_repo); storage.replace(storage_repo);
@@ -311,7 +318,7 @@ namespace seafile::fs {
return {}; return {};
} }
std::vector<RepoEntry> SeafileStore::queryDirectChildren( std::vector<RepoEntry> SeafileStore::queryDirectoryChildren(
const std::string &repo_id, const std::string &parent_path) { const std::string &repo_id, const std::string &parent_path) {
std::lock_guard lock(database->mutex); std::lock_guard lock(database->mutex);
auto &storage = this->database->storage; auto &storage = this->database->storage;
@@ -394,12 +401,12 @@ namespace seafile::fs {
} }
const auto inner_path = joinPath(parts, 1); const auto inner_path = joinPath(parts, 1);
auto children = queryDirectChildren(repo->id, inner_path); auto children = queryDirectoryChildren(repo->id, inner_path);
if (children.empty()) { if (children.empty()) {
if (const auto res = fetchAndStoreRepoDir(repo->id, inner_path); !res) { if (const auto res = fetchAndStoreRepoDir(repo->id, inner_path); !res) {
return tl::make_unexpected(res.error()); return tl::make_unexpected(res.error());
} }
children = queryDirectChildren(repo->id, inner_path); children = queryDirectoryChildren(repo->id, inner_path);
} }
return std::variant<std::vector<RepoInfo>, std::vector<RepoEntry> >(std::move(children)); return std::variant<std::vector<RepoInfo>, std::vector<RepoEntry> >(std::move(children));
} }