Browse Source

Lithium update (#6023)

* Lithium update

* Lithium update

* Lithium update

* Lithium: Remove json caching.

* Lithium: Fix cached queries.
Matthieu Garrigues 4 years ago
parent
commit
5cc9409172

+ 1 - 1
frameworks/C++/lithium/compile_and_start_clang.sh

@@ -1,7 +1,7 @@
 #! /bin/sh
 #! /bin/sh
 
 
 DB_FLAG=$1
 DB_FLAG=$1
-COMMIT=941b701ac884b1d7f050b721fe444b6831563239
+COMMIT=58334f62653a330863cfff633b50f3cfc567e527
 
 
 if [ $DB_FLAG = "TFB_MYSQL" ]; then
 if [ $DB_FLAG = "TFB_MYSQL" ]; then
   CXX_FLAGS="-I /usr/include/mariadb  -lmariadbclient "
   CXX_FLAGS="-I /usr/include/mariadb  -lmariadbclient "

+ 1 - 1
frameworks/C++/lithium/compile_and_start_gcc.sh

@@ -1,7 +1,7 @@
 #! /bin/sh
 #! /bin/sh
 
 
 DB_FLAG=$1
 DB_FLAG=$1
-COMMIT=8564c2286d0ae9508fe7d3c8dbf65b7f299f40af
+COMMIT=58334f62653a330863cfff633b50f3cfc567e527
 
 
 if [ $DB_FLAG = "TFB_MYSQL" ]; then
 if [ $DB_FLAG = "TFB_MYSQL" ]; then
   CXX_FLAGS="-I /usr/include/mariadb  -lmariadbclient "
   CXX_FLAGS="-I /usr/include/mariadb  -lmariadbclient "

+ 21 - 6
frameworks/C++/lithium/lithium.cc

@@ -54,7 +54,23 @@ void siege(int port) {
 }
 }
 #endif
 #endif
 
 
-lru_cache<int, decltype(mmm(s::id = int(), s::randomNumber = int()))> world_cache(10000);
+template <typename T>
+struct cache {
+
+  void insert(T o) { 
+    buffer.push_back(o);
+  }
+
+  std::vector<const T*> get_array(const std::vector<int>& ids) const {
+    std::vector<const T*> res;
+    for (int i = 0; i < ids.size(); i++) res.push_back(&buffer[ids[i]]);
+    return res;
+  }
+
+  std::vector<T> buffer;
+};
+
+cache<decltype(mmm(s::id = int(), s::randomNumber = int()))> world_cache;
 
 
 int main(int argc, char* argv[]) {
 int main(int argc, char* argv[]) {
 
 
@@ -142,7 +158,7 @@ int main(int argc, char* argv[]) {
   };
   };
 
 
   random_numbers.connect().forall([&] (const auto& number) {
   random_numbers.connect().forall([&] (const auto& number) {
-    world_cache(number.id, [&] { return metamap_clone(number); });
+    world_cache.insert(metamap_clone(number));
   });
   });
 
 
   my_api.get("/cached-worlds") = [&](http_request& request, http_response& response) {
   my_api.get("/cached-worlds") = [&](http_request& request, http_response& response) {
@@ -152,11 +168,10 @@ int main(int argc, char* argv[]) {
     
     
     N = std::max(1, std::min(N, 500));
     N = std::max(1, std::min(N, 500));
 
 
-    std::vector<decltype(random_numbers.all_fields())> numbers(N);
+    std::vector<int> ids(N);
     for (int i = 0; i < N; i++)
     for (int i = 0; i < N; i++)
-      numbers[i] = world_cache(1 + rand() % 10000);
-
-    response.write_json(numbers);
+      ids[i] = 1 + rand() % 10000;
+    response.write_json(world_cache.get_array(ids));
   };
   };
 
 
   my_api.get("/updates") = [&](http_request& request, http_response& response) {
   my_api.get("/updates") = [&](http_request& request, http_response& response) {