Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Implemented qglobals replacement and/or alternative called "Data Buck…
…ets" see changelog for more details
- Loading branch information
Showing
12 changed files
with
234 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
CREATE TABLE `data_buckets` ( | ||
`id` bigint(11) unsigned NOT NULL AUTO_INCREMENT, | ||
`key` varchar(100) DEFAULT NULL, | ||
`value` text, | ||
`expires` int(11) unsigned DEFAULT '0', | ||
PRIMARY KEY (`id`), | ||
KEY `key_index` (`key`) USING BTREE | ||
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
#include "data_bucket.h" | ||
#include <utility> | ||
#include "../common/string_util.h" | ||
#include "zonedb.h" | ||
#include <ctime> | ||
|
||
/** | ||
* Persists data via bucket_name as key | ||
* @param bucket_key | ||
* @param bucket_value | ||
*/ | ||
void DataBucket::SetData(std::string bucket_key, std::string bucket_value, uint32 expires_at_unix) { | ||
uint64 bucket_id = DataBucket::DoesBucketExist(bucket_key); | ||
|
||
std::string query; | ||
|
||
if (bucket_id > 0) { | ||
std::string update_expired_time; | ||
if (expires_at_unix > 0) { | ||
update_expired_time = StringFormat(", `expires` = %u ", expires_at_unix); | ||
} | ||
|
||
query = StringFormat( | ||
"UPDATE `data_buckets` SET `value` = '%s' %s WHERE `id` = %i", | ||
EscapeString(bucket_value).c_str(), | ||
EscapeString(update_expired_time).c_str(), | ||
bucket_id | ||
); | ||
} | ||
else { | ||
query = StringFormat( | ||
"INSERT INTO `data_buckets` (`key`, `value`, `expires`) VALUES ('%s', '%s', '%u')", | ||
EscapeString(bucket_key).c_str(), | ||
EscapeString(bucket_value).c_str(), | ||
expires_at_unix | ||
); | ||
} | ||
|
||
database.QueryDatabase(query); | ||
} | ||
|
||
/** | ||
* Retrieves data via bucket_name as key | ||
* @param bucket_key | ||
* @return | ||
*/ | ||
std::string DataBucket::GetData(std::string bucket_key) { | ||
std::string query = StringFormat( | ||
"SELECT `value` from `data_buckets` WHERE `key` = '%s' AND (`expires` > %lld OR `expires` = 0) LIMIT 1", | ||
bucket_key.c_str(), | ||
(long long) std::time(nullptr) | ||
); | ||
|
||
auto results = database.QueryDatabase(query); | ||
if (!results.Success()) { | ||
return std::string(); | ||
} | ||
|
||
if (results.RowCount() != 1) | ||
return std::string(); | ||
|
||
auto row = results.begin(); | ||
|
||
return std::string(row[0]); | ||
} | ||
|
||
/** | ||
* Checks for bucket existence by bucket_name key | ||
* @param bucket_key | ||
* @return | ||
*/ | ||
uint64 DataBucket::DoesBucketExist(std::string bucket_key) { | ||
std::string query = StringFormat( | ||
"SELECT `id` from `data_buckets` WHERE `key` = '%s' AND (`expires` > %lld OR `expires` = 0) LIMIT 1", | ||
EscapeString(bucket_key).c_str(), | ||
(long long) std::time(nullptr) | ||
); | ||
|
||
auto results = database.QueryDatabase(query); | ||
if (!results.Success()) { | ||
return 0; | ||
} | ||
|
||
auto row = results.begin(); | ||
if (results.RowCount() != 1) | ||
return 0; | ||
|
||
return std::stoull(row[0]); | ||
} | ||
|
||
/** | ||
* Deletes data bucket by key | ||
* @param bucket_key | ||
* @return | ||
*/ | ||
bool DataBucket::DeleteData(std::string bucket_key) { | ||
std::string query = StringFormat( | ||
"DELETE FROM `data_buckets` WHERE `key` = '%s' AND (`expires` > %lld OR `expires` = 0)", | ||
EscapeString(bucket_key).c_str() | ||
); | ||
|
||
auto results = database.QueryDatabase(query); | ||
|
||
return results.Success(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// Created by Akkadius on 7/7/18. | ||
// | ||
|
||
#ifndef EQEMU_DATABUCKET_H | ||
#define EQEMU_DATABUCKET_H | ||
|
||
|
||
#include <string> | ||
#include "../common/types.h" | ||
|
||
class DataBucket { | ||
public: | ||
static void SetData(std::string bucket_key, std::string bucket_value, uint32 expires_at_unix = 0); | ||
static bool DeleteData(std::string bucket_key); | ||
static std::string GetData(std::string bucket_key); | ||
private: | ||
static uint64 DoesBucketExist(std::string bucket_key); | ||
}; | ||
|
||
|
||
#endif //EQEMU_DATABUCKET_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters