Pārlūkot izejas kodu

Fix accidental sharing of ConnectionPool across threads.

Sönke Ludwig 9 gadi atpakaļ
vecāks
revīzija
491df55a55
1 mainītis faili ar 11 papildinājumiem un 12 dzēšanām
  1. 11 12
      frameworks/D/vibed/source/mongodb.d

+ 11 - 12
frameworks/D/vibed/source/mongodb.d

@@ -23,20 +23,19 @@ shared static this()
 	listenHTTP(settings, router);
 }
 
-class WebInterface {
-	private {
-		MongoCollection _worldCollection;
-		MongoCollection _fortuneCollection;
-	}
+MongoCollection _worldCollection;
+MongoCollection _fortuneCollection;
 
-	this()
-	{
-		import std.process : environment;
-		auto db = connectMongoDB(environment["DBHOST"]);
-		_worldCollection = db.getCollection("hello_world.World");
-		_fortuneCollection = db.getCollection("hello_world.Fortune");
-	}
+// sets up the MongoDB connection pools for each thread
+static this()
+{
+	import std.process : environment;
+	auto db = connectMongoDB(environment["DBHOST"]);
+	_worldCollection = db.getCollection("hello_world.World");
+	_fortuneCollection = db.getCollection("hello_world.Fortune");
+}
 
+class WebInterface {
 	// GET /
 	void get()
 	{