diff --git a/native/cpp/CommonCpp/DatabaseManagers/DatabaseManager.cpp b/native/cpp/CommonCpp/DatabaseManagers/DatabaseManager.cpp --- a/native/cpp/CommonCpp/DatabaseManagers/DatabaseManager.cpp +++ b/native/cpp/CommonCpp/DatabaseManagers/DatabaseManager.cpp @@ -398,17 +398,9 @@ throw std::runtime_error(errorMessage); } - std::string getAllBlobServiceMediaSQL = - "SELECT * FROM media WHERE uri LIKE 'comm-blob-service://%';"; - std::vector blobServiceMedia = getAllEntities( - DatabaseManager::mainConnectionManager->getConnection(), - getAllBlobServiceMediaSQL); - - for (const auto &media : blobServiceMedia) { - std::string blobServiceURI = media.uri; - std::string blobHash = - SQLiteUtils::blobHashFromBlobServiceURI(blobServiceURI); - tempAttachmentsFile << blobHash << "\n"; + auto holders = DatabaseManager::getQueryExecutor().getHolders(); + for (const auto &holder : holders) { + tempAttachmentsFile << holder.hash << "\n"; } tempAttachmentsFile.close(); diff --git a/native/cpp/CommonCpp/DatabaseManagers/NativeSQLiteConnectionManager.cpp b/native/cpp/CommonCpp/DatabaseManagers/NativeSQLiteConnectionManager.cpp --- a/native/cpp/CommonCpp/DatabaseManagers/NativeSQLiteConnectionManager.cpp +++ b/native/cpp/CommonCpp/DatabaseManagers/NativeSQLiteConnectionManager.cpp @@ -14,8 +14,6 @@ namespace comm { -const std::string BLOB_SERVICE_PREFIX = "comm-blob-service://"; - const int IV_LENGTH = 12; const int TAG_LENGTH = 16; @@ -144,7 +142,7 @@ handleSQLiteError( getOperationResult, "Failed to extract operation from log iterator."); - if (std::string(tableName) != "media") { + if (std::string(tableName) != "holders") { continue; } @@ -152,23 +150,19 @@ continue; } - sqlite3_value *uriFromMediaRow; - // In "media" table "uri" column has index 3 (starting from 0) - int getURIResult = sqlite3changeset_new(patchsetIter, 3, &uriFromMediaRow); + sqlite3_value *hashResult; + int getHashResult = sqlite3changeset_new(patchsetIter, 0, &hashResult); handleSQLiteError( - getURIResult, - "Failed to extract uri value of media row from log iterator."); + getHashResult, + "Failed to extract hash value of holder row from log iterator"); - if (!uriFromMediaRow) { + if (!hashResult) { continue; } - std::string uri = std::string( - reinterpret_cast(sqlite3_value_text(uriFromMediaRow))); - if (uri.compare(0, BLOB_SERVICE_PREFIX.size(), BLOB_SERVICE_PREFIX)) { - continue; - } - attachments.push_back(uri.substr(BLOB_SERVICE_PREFIX.size())); + std::string hash = std::string( + reinterpret_cast(sqlite3_value_text(hashResult))); + attachments.push_back(hash); } handleSQLiteError( diff --git a/native/cpp/CommonCpp/DatabaseManagers/SQLiteUtils.h b/native/cpp/CommonCpp/DatabaseManagers/SQLiteUtils.h --- a/native/cpp/CommonCpp/DatabaseManagers/SQLiteUtils.h +++ b/native/cpp/CommonCpp/DatabaseManagers/SQLiteUtils.h @@ -12,7 +12,6 @@ static int getDatabaseVersion(sqlite3 *db); static bool setDatabaseVersion(sqlite3 *db, int db_version); static void setEncryptionKey(sqlite3 *db, const std::string &encryptionKey); - static std::string blobHashFromBlobServiceURI(const std::string &mediaURI); static bool fileExists(const std::string &filePath); static void attemptDeleteFile(const std::string &filePath, const char *errorMessage); diff --git a/native/cpp/CommonCpp/DatabaseManagers/SQLiteUtils.cpp b/native/cpp/CommonCpp/DatabaseManagers/SQLiteUtils.cpp --- a/native/cpp/CommonCpp/DatabaseManagers/SQLiteUtils.cpp +++ b/native/cpp/CommonCpp/DatabaseManagers/SQLiteUtils.cpp @@ -64,15 +64,6 @@ } } -// This is a temporary solution. In future we want to keep -// a separate table for blob hashes. Tracked on Linear: -// https://linear.app/comm/issue/ENG-6261/introduce-blob-hash-table -std::string -SQLiteUtils::blobHashFromBlobServiceURI(const std::string &mediaURI) { - static const std::string blobServicePrefix = "comm-blob-service://"; - return mediaURI.substr(blobServicePrefix.size()); -} - bool SQLiteUtils::fileExists(const std::string &filePath) { std::ifstream file(filePath.c_str()); return file.good();