|
@@ -1,6 +1,8 @@
|
|
#include "worldcontroller.h"
|
|
#include "worldcontroller.h"
|
|
#include "world.h"
|
|
#include "world.h"
|
|
|
|
+#include "pworld.h"
|
|
#include "mngworld.h"
|
|
#include "mngworld.h"
|
|
|
|
+#include <TCache>
|
|
|
|
|
|
|
|
|
|
void WorldController::index()
|
|
void WorldController::index()
|
|
@@ -31,7 +33,7 @@ void WorldController::queries()
|
|
void WorldController::queries(const QString &num)
|
|
void WorldController::queries(const QString &num)
|
|
{
|
|
{
|
|
QVariantList worlds;
|
|
QVariantList worlds;
|
|
- int d = qMin(qMax(num.toInt(), 1), 500);
|
|
|
|
|
|
+ int d = std::min(std::max(num.toInt(), 1), 500);
|
|
|
|
|
|
for (int i = 0; i < d; ++i) {
|
|
for (int i = 0; i < d; ++i) {
|
|
int id = Tf::random(1, 10000);
|
|
int id = Tf::random(1, 10000);
|
|
@@ -40,6 +42,37 @@ void WorldController::queries(const QString &num)
|
|
renderJson(worlds);
|
|
renderJson(worlds);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+void WorldController::cached_queries()
|
|
|
|
+{
|
|
|
|
+ cached_queries("1");
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void WorldController::cached_queries(const QString &num)
|
|
|
|
+{
|
|
|
|
+ constexpr int SECONDS = 60 * 10; // cache time
|
|
|
|
+ QVariantList worlds;
|
|
|
|
+ QVariantMap world;
|
|
|
|
+ int d = std::min(std::max(num.toInt(), 1), 500);
|
|
|
|
+
|
|
|
|
+ for (int i = 0; i < d; ++i) {
|
|
|
|
+ int id = Tf::random(1, 10000);
|
|
|
|
+ auto key = QByteArray::number(id);
|
|
|
|
+ auto randomNumber = Tf::cache()->get(key); // Gets from cache
|
|
|
|
+
|
|
|
|
+ if (randomNumber.isEmpty()) {
|
|
|
|
+ auto w = World::get(id);
|
|
|
|
+ worlds << w.toVariantMap();
|
|
|
|
+ // Cache the value
|
|
|
|
+ Tf::cache()->set(key, QByteArray::number(w.randomNumber()), SECONDS);
|
|
|
|
+ } else {
|
|
|
|
+ world.insert("id", id);
|
|
|
|
+ world.insert("randomNumber", randomNumber.toInt());
|
|
|
|
+ worlds << world;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ renderJson(worlds);
|
|
|
|
+}
|
|
|
|
+
|
|
void WorldController::random()
|
|
void WorldController::random()
|
|
{
|
|
{
|
|
int id = Tf::random(1, 10000);
|
|
int id = Tf::random(1, 10000);
|
|
@@ -129,7 +162,7 @@ void WorldController::updates()
|
|
void WorldController::updates(const QString &num)
|
|
void WorldController::updates(const QString &num)
|
|
{
|
|
{
|
|
QVariantList worlds;
|
|
QVariantList worlds;
|
|
- int d = qMin(qMax(num.toInt(), 1), 500);
|
|
|
|
|
|
+ int d = std::min(std::max(num.toInt(), 1), 500);
|
|
World world;
|
|
World world;
|
|
|
|
|
|
for (int i = 0; i < d; ++i) {
|
|
for (int i = 0; i < d; ++i) {
|
|
@@ -153,10 +186,87 @@ void WorldController::remove(const QString &pk)
|
|
redirect(urla("index"));
|
|
redirect(urla("index"));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/*
|
|
|
|
+ * PostgreSQL
|
|
|
|
+ */
|
|
|
|
+void WorldController::prandom()
|
|
|
|
+{
|
|
|
|
+ int id = Tf::random(1, 10000);
|
|
|
|
+ PWorld world = PWorld::get(id);
|
|
|
|
+ renderJson(world.toVariantMap());
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void WorldController::pqueries()
|
|
|
|
+{
|
|
|
|
+ pqueries("1");
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void WorldController::pqueries(const QString &num)
|
|
|
|
+{
|
|
|
|
+ QVariantList worlds;
|
|
|
|
+ int d = std::min(std::max(num.toInt(), 1), 500);
|
|
|
|
+
|
|
|
|
+ for (int i = 0; i < d; ++i) {
|
|
|
|
+ int id = Tf::random(1, 10000);
|
|
|
|
+ worlds << PWorld::get(id).toVariantMap();
|
|
|
|
+ }
|
|
|
|
+ renderJson(worlds);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void WorldController::cached_pqueries()
|
|
|
|
+{
|
|
|
|
+ cached_pqueries("1");
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void WorldController::cached_pqueries(const QString &num)
|
|
|
|
+{
|
|
|
|
+ constexpr int SECONDS = 60 * 10; // cache time
|
|
|
|
+ QVariantList worlds;
|
|
|
|
+ QVariantMap world;
|
|
|
|
+ int d = std::min(std::max(num.toInt(), 1), 500);
|
|
|
|
+
|
|
|
|
+ for (int i = 0; i < d; ++i) {
|
|
|
|
+ int id = Tf::random(1, 10000);
|
|
|
|
+ auto key = QByteArray::number(id);
|
|
|
|
+ auto randomNumber = Tf::cache()->get(key); // Gets from cache
|
|
|
|
+
|
|
|
|
+ if (randomNumber.isEmpty()) {
|
|
|
|
+ auto w = PWorld::get(id);
|
|
|
|
+ worlds << w.toVariantMap();
|
|
|
|
+ // Cache the value
|
|
|
|
+ Tf::cache()->set(key, QByteArray::number(w.randomNumber()), SECONDS);
|
|
|
|
+ } else {
|
|
|
|
+ world.insert("id", id);
|
|
|
|
+ world.insert("randomnumber", randomNumber.toInt());
|
|
|
|
+ worlds << world;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ renderJson(worlds);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void WorldController::pupdates(const QString &num)
|
|
|
|
+{
|
|
|
|
+ QVariantList worlds;
|
|
|
|
+ int d = std::min(std::max(num.toInt(), 1), 500);
|
|
|
|
+ PWorld world;
|
|
|
|
+
|
|
|
|
+ for (int i = 0; i < d; ++i) {
|
|
|
|
+ int id = Tf::random(1, 10000);
|
|
|
|
+ world = PWorld::get(id);
|
|
|
|
+ world.setRandomNumber( Tf::random(1, 10000) );
|
|
|
|
+ world.update();
|
|
|
|
+ worlds << world.toVariantMap();
|
|
|
|
+ }
|
|
|
|
+ renderJson(worlds);
|
|
|
|
+}
|
|
|
|
|
|
|
|
+void WorldController::pupdates()
|
|
|
|
+{
|
|
|
|
+ pupdates("1");
|
|
|
|
+}
|
|
|
|
|
|
/*
|
|
/*
|
|
- MongoDB
|
|
|
|
|
|
+ * MongoDB
|
|
*/
|
|
*/
|
|
void WorldController::mqueries()
|
|
void WorldController::mqueries()
|
|
{
|
|
{
|
|
@@ -166,7 +276,7 @@ void WorldController::mqueries()
|
|
void WorldController::mqueries(const QString &num)
|
|
void WorldController::mqueries(const QString &num)
|
|
{
|
|
{
|
|
QVariantList worlds;
|
|
QVariantList worlds;
|
|
- int d = qMin(qMax(num.toInt(), 1), 500);
|
|
|
|
|
|
+ int d = std::min(std::max(num.toInt(), 1), 500);
|
|
|
|
|
|
for (int i = 0; i < d; ++i) {
|
|
for (int i = 0; i < d; ++i) {
|
|
QString id = QString::number(Tf::random(1, 10000));
|
|
QString id = QString::number(Tf::random(1, 10000));
|
|
@@ -175,6 +285,37 @@ void WorldController::mqueries(const QString &num)
|
|
renderJson(worlds);
|
|
renderJson(worlds);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+void WorldController::cached_mqueries()
|
|
|
|
+{
|
|
|
|
+ cached_mqueries("1");
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void WorldController::cached_mqueries(const QString &num)
|
|
|
|
+{
|
|
|
|
+ constexpr int SECONDS = 60 * 10; // cache time
|
|
|
|
+ QVariantList worlds;
|
|
|
|
+ QVariantMap world;
|
|
|
|
+ int d = std::min(std::max(num.toInt(), 1), 500);
|
|
|
|
+
|
|
|
|
+ for (int i = 0; i < d; ++i) {
|
|
|
|
+ int id = Tf::random(1, 10000);
|
|
|
|
+ QByteArray key = QByteArray::number(id);
|
|
|
|
+ auto randomNumber = Tf::cache()->get(key); // Gets from cache
|
|
|
|
+
|
|
|
|
+ if (randomNumber.isEmpty()) {
|
|
|
|
+ auto w = MngWorld::get(key);
|
|
|
|
+ worlds << w.toVariantMap();
|
|
|
|
+ // Cache the value
|
|
|
|
+ Tf::cache()->set(key, QByteArray::number(w.randomNumber()), SECONDS);
|
|
|
|
+ } else {
|
|
|
|
+ world.insert("id", id);
|
|
|
|
+ world.insert("randomNumber", randomNumber.toInt());
|
|
|
|
+ worlds << world;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ renderJson(worlds);
|
|
|
|
+}
|
|
|
|
+
|
|
void WorldController::mrandom()
|
|
void WorldController::mrandom()
|
|
{
|
|
{
|
|
QString id = QString::number(Tf::random(1, 10000));
|
|
QString id = QString::number(Tf::random(1, 10000));
|
|
@@ -190,7 +331,7 @@ void WorldController::mupdates()
|
|
void WorldController::mupdates(const QString &num)
|
|
void WorldController::mupdates(const QString &num)
|
|
{
|
|
{
|
|
QVariantList worlds;
|
|
QVariantList worlds;
|
|
- int d = qMin(qMax(num.toInt(), 1), 500);
|
|
|
|
|
|
+ int d = std::min(std::max(num.toInt(), 1), 500);
|
|
MngWorld world;
|
|
MngWorld world;
|
|
|
|
|
|
for (int i = 0; i < d; ++i) {
|
|
for (int i = 0; i < d; ++i) {
|