refactor: Simplify getting shared data directory URL

This commit is contained in:
Lars Toenning
2024-04-29 21:46:23 +02:00
parent 14c045e7b4
commit 89544d1ecb
4 changed files with 6 additions and 32 deletions

View File

@@ -97,25 +97,9 @@ namespace BlackCore::Data
m_dbDebugFlag = debug;
}
CUrl CGlobalSetup::buildDbDataDirectoryUrl(const CUrl &candidate)
CUrl CGlobalSetup::getSharedDbDataDirectoryUrl()
{
if (candidate.isEmpty()) return CUrl(); // not possible
static const QString version(QString(schemaVersionString()).append("/"));
if (candidate.pathEndsWith("dbdata") || candidate.pathEndsWith("dbdata/")) { return candidate; }
CUrl url(candidate);
if (candidate.pathEndsWith(schemaVersionString()) || candidate.pathEndsWith(version))
{
url.appendPath("/dbdata");
}
else if (candidate.pathEndsWith("shared") || candidate.pathEndsWith("shared/"))
{
url.appendPath(CGlobalSetup::schemaVersionString() + "/dbdata/");
}
else
{
url.appendPath("shared/" + CGlobalSetup::schemaVersionString() + "/dbdata/");
}
return url;
return m_sharedUrl.withAppendedPath(CGlobalSetup::schemaVersionString() + "/dbdata/");
}
CServerList CGlobalSetup::getPredefinedServersPlusHardcodedServers() const

View File

@@ -152,6 +152,9 @@ namespace BlackCore::Data
//! To string with separator
QString convertToQString(const QString &separator, bool i18n = false) const;
//! Get shared DB data directory URL
BlackMisc::Network::CUrl getSharedDbDataDirectoryUrl();
//! \copydoc BlackMisc::Mixin::Index::propertyByIndex
QVariant propertyByIndex(BlackMisc::CPropertyIndexRef index) const;
@@ -161,9 +164,6 @@ namespace BlackCore::Data
//! Schema version (shared files, bootstrap file)
static const QString &schemaVersionString();
//! Build the full dbdata directory URL from shared URL
static BlackMisc::Network::CUrl buildDbDataDirectoryUrl(const BlackMisc::Network::CUrl &candidate);
private:
int m_dbHttpPort = 80; //!< port
int m_dbHttpsPort = 443; //!< SSL port

View File

@@ -478,7 +478,7 @@ namespace BlackCore::Db
return this->getDbServiceBaseUrl().withAppendedPath("/service");
case CDbFlags::SharedInfoOnly:
case CDbFlags::Shared:
return CDatabaseReader::getSharedDbdataDirectoryUrl();
return sApp->getGlobalSetup().getSharedDbDataDirectoryUrl();
default:
qFatal("Wrong mode");
break;
@@ -693,13 +693,6 @@ namespace BlackCore::Db
return dbUrl;
}
CUrl CDatabaseReader::getSharedDbdataDirectoryUrl()
{
const CUrlList sharedUrls = sApp->getGlobalSetup().getSwiftSharedUrls();
Q_ASSERT_X(!sharedUrls.empty(), Q_FUNC_INFO, "Need at least one shared URL");
return CGlobalSetup::buildDbDataDirectoryUrl(sharedUrls[0]);
}
void CDatabaseReader::cacheHasChanged(CEntityFlags::Entity entities)
{
this->emitReadSignalPerSingleCachedEntity(entities, false);

View File

@@ -343,9 +343,6 @@ namespace BlackCore::Db
//! DB base URL
static const BlackMisc::Network::CUrl &getDbUrl();
//! shared "dbdata" directory URL
static BlackMisc::Network::CUrl getSharedDbdataDirectoryUrl();
//! File name for given mode, either php service or shared file name
static QString fileNameForMode(BlackMisc::Network::CEntityFlags::Entity entity, BlackMisc::Db::CDbFlags::DataRetrievalModeFlag mode);