فهرست منبع

1.db cache这个功能比较鸡肋,实在需要cache可以自己搞个进程来cache
2.TaskCompletionSource是没有非泛型实现的,导致之前必须使用TaskCompletionSource<bool>,ETTask有非泛型实现,所以不需要这个bool了

tanghai 7 سال پیش
والد
کامیت
eb5dcc50c7
39فایلهای تغییر یافته به همراه134 افزوده شده و 302 حذف شده
  1. 4 8
      Proto/InnerMessage.proto
  2. 0 1
      Server/App/Program.cs
  3. 1 2
      Server/Hotfix/Handler/Actor_TestHandler.cs
  4. 0 1
      Server/Hotfix/Handler/Actor_TransferHandler.cs
  5. 0 1
      Server/Hotfix/Handler/C2M_TestRequestHandler.cs
  6. 0 3
      Server/Hotfix/Module/ActorLocation/ActorLocationSenderSystem.cs
  7. 1 2
      Server/Hotfix/Module/ActorLocation/LocationProxyComponentSystem.cs
  8. 0 1
      Server/Hotfix/Module/Benchmark/BenchmarkComponentSystem.cs
  9. 0 1
      Server/Hotfix/Module/Benchmark/WebSocketBenchmarkComponentSystem.cs
  10. 4 6
      Server/Hotfix/Module/BigWorld/LockComponentSystem.cs
  11. 4 6
      Server/Hotfix/Module/BigWorld/MasterComponentSystem.cs
  12. 11 13
      Server/Hotfix/Module/DB/DBProxyComponentSystem.cs
  13. 2 13
      Server/Hotfix/Module/DB/DBQueryBatchRequestHandler.cs
  14. 1 2
      Server/Hotfix/Module/DB/DBQueryJsonRequestHandler.cs
  15. 1 7
      Server/Hotfix/Module/DB/DBQueryRequestHandler.cs
  16. 2 10
      Server/Hotfix/Module/DB/DBSaveBatchRequestHandler.cs
  17. 2 6
      Server/Hotfix/Module/DB/DBSaveRequestHandler.cs
  18. 0 1
      Server/Hotfix/Module/Demo/C2M_TestActorRequestHandler.cs
  19. 0 1
      Server/Hotfix/Module/Demo/C2R_LoginHandler.cs
  20. 0 1
      Server/Hotfix/Module/Demo/Frame_ClickMapHandler.cs
  21. 1 3
      Server/Hotfix/Module/Demo/G2M_SessionDisconnectHandler.cs
  22. 0 1
      Server/Hotfix/Module/Demo/UnitPathComponentSystem.cs
  23. 1 2
      Server/Hotfix/Module/Message/InnerMessageDispatcher.cs
  24. 1 2
      Server/Hotfix/Module/Message/NetInnerComponentSystem.cs
  25. 0 1
      Server/Hotfix/Module/Message/OuterMessageDispatcher.cs
  26. 1 1
      Server/Model/Module/BigWorld/LockComponent.cs
  27. 2 2
      Server/Model/Module/BigWorld/MasterComponent.cs
  28. 0 147
      Server/Model/Module/DB/DBCacheComponent.cs
  29. 65 5
      Server/Model/Module/DB/DBComponent.cs
  30. 2 7
      Server/Model/Module/DB/DBQueryBatchTask.cs
  31. 1 9
      Server/Model/Module/DB/DBQueryTask.cs
  32. 4 4
      Server/Model/Module/DB/DBSaveBatchTask.cs
  33. 4 4
      Server/Model/Module/DB/DBSaveTask.cs
  34. 1 8
      Server/Model/Module/Message/InnerMessage.cs
  35. 6 7
      Unity/Assets/Model/Component/SceneChangeComponent.cs
  36. 5 5
      Unity/Assets/Model/Entity/UnityWebRequestAsync.cs
  37. 5 5
      Unity/Assets/Model/Module/AssetsBundle/AssetsLoaderAsync.cs
  38. 1 3
      Unity/Assets/Model/Module/Message/NetOuterComponentSystem.cs
  39. 1 0
      Unity/Assets/Model/Module/Message/OuterOpcode.cs

+ 4 - 8
Proto/InnerMessage.proto

@@ -60,9 +60,8 @@
 	{
 		int32 RpcId = 90;
 
-		bool NeedCache = 1;
-		string CollectionName = 2;
-		ComponentWithId Component = 3;
+		string CollectionName = 1;
+		ComponentWithId Component = 2;
 	}
 
 
@@ -77,9 +76,8 @@
 	{
 		int32 RpcId = 90;
 
-		bool NeedCache = 1;
-		string CollectionName = 2;
-		repeated ComponentWithId Components = 3;
+		string CollectionName = 1;
+		repeated ComponentWithId Components = 2;
 	}
 
 	message DBSaveResponse // IResponse
@@ -94,7 +92,6 @@
 		int32 RpcId = 90;
 		int64 Id = 1;
 		string CollectionName = 2;
-		bool NeedCache = 3;
 	}
 
 	message DBQueryResponse // IResponse
@@ -111,7 +108,6 @@
 		int32 RpcId = 90;
 		string CollectionName = 1;
 		repeated int64 IdList = 2;
-		bool NeedCache = 3;
 	}
 
 	message DBQueryBatchResponse // IResponse

+ 0 - 1
Server/App/Program.cs

@@ -92,7 +92,6 @@ namespace App
 						
 						//Game.Scene.AddComponent<DBComponent>();
 						//Game.Scene.AddComponent<DBProxyComponent>();
-						//Game.Scene.AddComponent<DBCacheComponent>();
 						
 						// location server需要的组件
 						Game.Scene.AddComponent<LocationComponent>();

+ 1 - 2
Server/Hotfix/Handler/Actor_TestHandler.cs

@@ -1,5 +1,4 @@
-using System.Threading.Tasks;
-using ETModel;
+using ETModel;
 
 namespace ETHotfix
 {

+ 0 - 1
Server/Hotfix/Handler/Actor_TransferHandler.cs

@@ -1,6 +1,5 @@
 using System;
 using System.Net;
-using System.Threading.Tasks;
 using ETModel;
 
 namespace ETHotfix

+ 0 - 1
Server/Hotfix/Handler/C2M_TestRequestHandler.cs

@@ -1,5 +1,4 @@
 using System;
-using System.Threading.Tasks;
 using ETModel;
 
 namespace ETHotfix

+ 0 - 3
Server/Hotfix/Module/ActorLocation/ActorLocationSenderSystem.cs

@@ -1,7 +1,4 @@
 using System;
-using System.Collections.Generic;
-using System.Threading;
-using System.Threading.Tasks;
 using ETModel;
 
 namespace ETHotfix

+ 1 - 2
Server/Hotfix/Module/ActorLocation/LocationProxyComponentSystem.cs

@@ -1,5 +1,4 @@
-using System.Threading.Tasks;
-using ETModel;
+using ETModel;
 
 namespace ETHotfix
 {

+ 0 - 1
Server/Hotfix/Module/Benchmark/BenchmarkComponentSystem.cs

@@ -1,6 +1,5 @@
 using System;
 using System.Net;
-using System.Threading.Tasks;
 using ETModel;
 
 namespace ETHotfix

+ 0 - 1
Server/Hotfix/Module/Benchmark/WebSocketBenchmarkComponentSystem.cs

@@ -1,5 +1,4 @@
 using System;
-using System.Threading.Tasks;
 using ETModel;
 
 namespace ETHotfix

+ 4 - 6
Server/Hotfix/Module/BigWorld/LockComponentSystem.cs

@@ -1,7 +1,5 @@
 using System;
-using System.Collections.Generic;
 using System.Net;
-using System.Threading.Tasks;
 using ETModel;
 
 namespace ETHotfix
@@ -54,14 +52,14 @@ namespace ETHotfix
 			}
 		}
 
-		private static ETTask<bool> WaitLock(this LockComponent self)
+		private static ETTask WaitLock(this LockComponent self)
 		{
 			if (self.status == LockStatus.Locked)
 			{
 				return ETTask.FromResult(true);
 			}
 
-			ETTaskCompletionSource<bool> tcs = new ETTaskCompletionSource<bool>();
+			ETTaskCompletionSource tcs = new ETTaskCompletionSource();
 			self.queue.Enqueue(tcs);
 			return tcs.Task;
 		}
@@ -77,9 +75,9 @@ namespace ETHotfix
 
 				self.status = LockStatus.Locked;
 
-				foreach (ETTaskCompletionSource<bool> taskCompletionSource in self.queue)
+				foreach (ETTaskCompletionSource taskCompletionSource in self.queue)
 				{
-					taskCompletionSource.SetResult(true);
+					taskCompletionSource.SetResult();
 				}
 				self.queue.Clear();
 			}

+ 4 - 6
Server/Hotfix/Module/BigWorld/MasterComponentSystem.cs

@@ -1,6 +1,4 @@
-using System.Collections.Generic;
-using System.Net;
-using System.Threading.Tasks;
+using System.Net;
 using ETModel;
 
 namespace ETHotfix
@@ -17,7 +15,7 @@ namespace ETHotfix
 			self.ghostsAddress.Remove(address);
 		}
 
-		public static ETTask<bool> Lock(this MasterComponent self, IPEndPoint address)
+		public static ETTask Lock(this MasterComponent self, IPEndPoint address)
 		{
 			if (self.lockedAddress == null)
 			{
@@ -25,7 +23,7 @@ namespace ETHotfix
 				return ETTask.FromResult(true);
 			}
 
-			ETTaskCompletionSource<bool> tcs = new ETTaskCompletionSource<bool>();
+			ETTaskCompletionSource tcs = new ETTaskCompletionSource();
 			LockInfo lockInfo = new LockInfo(address, tcs);
 			self.queue.Enqueue(lockInfo);
 			return tcs.Task;
@@ -45,7 +43,7 @@ namespace ETHotfix
 			}
 			LockInfo lockInfo = self.queue.Dequeue();
 			self.lockedAddress = lockInfo.Address;
-			lockInfo.Tcs.SetResult(true);
+			lockInfo.Tcs.SetResult();
 		}
 	}
 }

+ 11 - 13
Server/Hotfix/Module/DB/DBProxyComponentSystem.cs

@@ -2,11 +2,9 @@
 using System.Collections.Generic;
 using System.Linq.Expressions;
 using System.Threading;
-using System.Threading.Tasks;
 using ETModel;
 using MongoDB.Bson;
 using MongoDB.Bson.Serialization;
-using MongoDB.Bson.Serialization.Serializers;
 using MongoDB.Driver;
 
 namespace ETHotfix
@@ -31,34 +29,34 @@ namespace ETHotfix
 			self.dbAddress = dbStartConfig.GetComponent<InnerConfig>().IPEndPoint;
 		}
 
-		public static async ETTask Save(this DBProxyComponent self, ComponentWithId component, bool needCache = true)
+		public static async ETTask Save(this DBProxyComponent self, ComponentWithId component)
 		{
 			Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(self.dbAddress);
-			await session.Call(new DBSaveRequest { Component = component, NeedCache = needCache});
+			await session.Call(new DBSaveRequest { Component = component });
 		}
 
-		public static async ETTask SaveBatch(this DBProxyComponent self, List<ComponentWithId> components, bool needCache = true)
+		public static async ETTask SaveBatch(this DBProxyComponent self, List<ComponentWithId> components)
 		{
 			Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(self.dbAddress);
-			await session.Call(new DBSaveBatchRequest { Components = components, NeedCache = needCache});
+			await session.Call(new DBSaveBatchRequest { Components = components });
 		}
 
-		public static async ETTask Save(this DBProxyComponent self, ComponentWithId component, bool needCache, CancellationToken cancellationToken)
+		public static async ETTask Save(this DBProxyComponent self, ComponentWithId component, CancellationToken cancellationToken)
 		{
 			Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(self.dbAddress);
-			await session.Call(new DBSaveRequest { Component = component, NeedCache = needCache}, cancellationToken);
+			await session.Call(new DBSaveRequest { Component = component }, cancellationToken);
 		}
 
 		public static async ETVoid SaveLog(this DBProxyComponent self, ComponentWithId component)
 		{
 			Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(self.dbAddress);
-			await session.Call(new DBSaveRequest { Component = component,  NeedCache = false, CollectionName = "Log" });
+			await session.Call(new DBSaveRequest { Component = component, CollectionName = "Log" });
 		}
 
-		public static async ETTask<T> Query<T>(this DBProxyComponent self, long id, bool needCache = true) where T: ComponentWithId
+		public static async ETTask<T> Query<T>(this DBProxyComponent self, long id) where T: ComponentWithId
 		{
 			Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(self.dbAddress);
-			DBQueryResponse dbQueryResponse = (DBQueryResponse)await session.Call(new DBQueryRequest { CollectionName = typeof(T).Name, Id = id, NeedCache = needCache });
+			DBQueryResponse dbQueryResponse = (DBQueryResponse)await session.Call(new DBQueryRequest { CollectionName = typeof(T).Name, Id = id });
 			return (T)dbQueryResponse.Component;
 		}
 		
@@ -78,10 +76,10 @@ namespace ETHotfix
 			return await self.Query<T>(json);
 		}
 
-		public static async ETTask<List<ComponentWithId>> Query<T>(this DBProxyComponent self, List<long> ids, bool needCache = true) where T : ComponentWithId
+		public static async ETTask<List<ComponentWithId>> Query<T>(this DBProxyComponent self, List<long> ids) where T : ComponentWithId
 		{
 			Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(self.dbAddress);
-			DBQueryBatchResponse dbQueryBatchResponse = (DBQueryBatchResponse)await session.Call(new DBQueryBatchRequest { CollectionName = typeof(T).Name, IdList = ids, NeedCache = needCache});
+			DBQueryBatchResponse dbQueryBatchResponse = (DBQueryBatchResponse)await session.Call(new DBQueryBatchRequest { CollectionName = typeof(T).Name, IdList = ids });
 			return dbQueryBatchResponse.Components;
 		}
 

+ 2 - 13
Server/Hotfix/Module/DB/DBQueryBatchRequestHandler.cs

@@ -1,5 +1,4 @@
 using System;
-using System.Collections.Generic;
 using ETModel;
 
 namespace ETHotfix
@@ -17,18 +16,8 @@ namespace ETHotfix
 			DBQueryBatchResponse response = new DBQueryBatchResponse();
 			try
 			{
-				DBCacheComponent dbCacheComponent = Game.Scene.GetComponent<DBCacheComponent>();
-				List<ComponentWithId> components = await dbCacheComponent.GetBatch(message.CollectionName, message.IdList);
-
-				response.Components = components;
-
-				if (message.NeedCache)
-				{
-					foreach (ComponentWithId component in components)
-					{
-						dbCacheComponent.AddToCache(component, message.CollectionName);
-					}
-				}
+				DBComponent dbComponent = Game.Scene.GetComponent<DBComponent>();
+				response.Components = await dbComponent.GetBatch(message.CollectionName, message.IdList);
 
 				reply(response);
 			}

+ 1 - 2
Server/Hotfix/Module/DB/DBQueryJsonRequestHandler.cs

@@ -17,8 +17,7 @@ namespace ETHotfix
 			DBQueryJsonResponse response = new DBQueryJsonResponse();
 			try
 			{
-				DBCacheComponent dbCacheComponent = Game.Scene.GetComponent<DBCacheComponent>();
-				List<ComponentWithId> components = await dbCacheComponent.GetJson(message.CollectionName, message.Json);
+				List<ComponentWithId> components = await Game.Scene.GetComponent<DBComponent>().GetJson(message.CollectionName, message.Json);
 				response.Components = components;
 
 				reply(response);

+ 1 - 7
Server/Hotfix/Module/DB/DBQueryRequestHandler.cs

@@ -16,16 +16,10 @@ namespace ETHotfix
 			DBQueryResponse response = new DBQueryResponse();
 			try
 			{
-				DBCacheComponent dbCacheComponent = Game.Scene.GetComponent<DBCacheComponent>();
-				ComponentWithId component = await dbCacheComponent.Get(message.CollectionName, message.Id);
+				ComponentWithId component = await Game.Scene.GetComponent<DBComponent>().Get(message.CollectionName, message.Id);
 
 				response.Component = component;
 
-				if (message.NeedCache && component != null)
-				{
-					dbCacheComponent.AddToCache(component, message.CollectionName);
-				}
-
 				reply(response);
 			}
 			catch (Exception e)

+ 2 - 10
Server/Hotfix/Module/DB/DBSaveBatchRequestHandler.cs

@@ -16,22 +16,14 @@ namespace ETHotfix
 			DBSaveBatchResponse response = new DBSaveBatchResponse();
 			try
 			{
-				DBCacheComponent dbCacheComponent = Game.Scene.GetComponent<DBCacheComponent>();
+				DBComponent dbComponent = Game.Scene.GetComponent<DBComponent>();
 
 				if (string.IsNullOrEmpty(message.CollectionName))
 				{
 					message.CollectionName = message.Components[0].GetType().Name;
 				}
 
-				if (message.NeedCache)
-				{
-					foreach (ComponentWithId component in message.Components)
-					{
-						dbCacheComponent.AddToCache(component, message.CollectionName);
-					}
-				}
-
-				await dbCacheComponent.AddBatch(message.Components, message.CollectionName);
+				await dbComponent.AddBatch(message.Components, message.CollectionName);
 
 				reply(response);
 			}

+ 2 - 6
Server/Hotfix/Module/DB/DBSaveRequestHandler.cs

@@ -16,17 +16,13 @@ namespace ETHotfix
 			DBSaveResponse response = new DBSaveResponse();
 			try
 			{
-				DBCacheComponent dbCacheComponent = Game.Scene.GetComponent<DBCacheComponent>();
+				DBComponent dbComponent = Game.Scene.GetComponent<DBComponent>();
 				if (string.IsNullOrEmpty(message.CollectionName))
 				{
 					message.CollectionName = message.Component.GetType().Name;
 				}
 
-				if (message.NeedCache)
-				{
-					dbCacheComponent.AddToCache(message.Component, message.CollectionName);
-				}
-				await dbCacheComponent.Add(message.Component, message.CollectionName);
+				await dbComponent.Add(message.Component, message.CollectionName);
 				reply(response);
 			}
 			catch (Exception e)

+ 0 - 1
Server/Hotfix/Module/Demo/C2M_TestActorRequestHandler.cs

@@ -1,5 +1,4 @@
 using System;
-using System.Threading.Tasks;
 using ETModel;
 
 namespace ETHotfix

+ 0 - 1
Server/Hotfix/Module/Demo/C2R_LoginHandler.cs

@@ -1,7 +1,6 @@
 using System;
 using System.Net;
 using ETModel;
-using MongoDB.Bson;
 
 namespace ETHotfix
 {

+ 0 - 1
Server/Hotfix/Module/Demo/Frame_ClickMapHandler.cs

@@ -1,6 +1,5 @@
 using ETModel;
 using PF;
-using ABPath = ETModel.ABPath;
 
 namespace ETHotfix
 {

+ 1 - 3
Server/Hotfix/Module/Demo/G2M_SessionDisconnectHandler.cs

@@ -1,6 +1,4 @@
-using System;
-using System.Threading.Tasks;
-using ETModel;
+using ETModel;
 
 namespace ETHotfix
 {

+ 0 - 1
Server/Hotfix/Module/Demo/UnitPathComponentSystem.cs

@@ -1,6 +1,5 @@
 using System.Collections.Generic;
 using System.Threading;
-using System.Threading.Tasks;
 using ETModel;
 using PF;
 

+ 1 - 2
Server/Hotfix/Module/Message/InnerMessageDispatcher.cs

@@ -1,5 +1,4 @@
-using System;
-using ETModel;
+using ETModel;
 
 namespace ETHotfix
 {

+ 1 - 2
Server/Hotfix/Module/Message/NetInnerComponentSystem.cs

@@ -1,5 +1,4 @@
-using System.Net;
-using ETModel;
+using ETModel;
 
 namespace ETHotfix
 {

+ 0 - 1
Server/Hotfix/Module/Message/OuterMessageDispatcher.cs

@@ -1,6 +1,5 @@
 using System;
 using ETModel;
-using Google.Protobuf;
 
 namespace ETHotfix
 {

+ 1 - 1
Server/Model/Module/BigWorld/LockComponent.cs

@@ -18,6 +18,6 @@ namespace ETModel
 		public LockStatus status = LockStatus.LockedNot;
 		public IPEndPoint address;
 		public int lockCount;
-		public readonly Queue<ETTaskCompletionSource<bool>> queue = new Queue<ETTaskCompletionSource<bool>>();
+		public readonly Queue<ETTaskCompletionSource> queue = new Queue<ETTaskCompletionSource>();
 	}
 }

+ 2 - 2
Server/Model/Module/BigWorld/MasterComponent.cs

@@ -6,9 +6,9 @@ namespace ETModel
 	public class LockInfo
 	{
 		public IPEndPoint Address;
-		public ETTaskCompletionSource<bool> Tcs;
+		public ETTaskCompletionSource Tcs;
 
-		public LockInfo(IPEndPoint address, ETTaskCompletionSource<bool> tcs)
+		public LockInfo(IPEndPoint address, ETTaskCompletionSource tcs)
 		{
 			this.Address = address;
 			this.Tcs = tcs;

+ 0 - 147
Server/Model/Module/DB/DBCacheComponent.cs

@@ -1,147 +0,0 @@
-using System.Collections.Generic;
-
-namespace ETModel
-{
-	[ObjectSystem]
-	public class DbCacheComponentSystem : AwakeSystem<DBCacheComponent>
-	{
-		public override void Awake(DBCacheComponent self)
-		{
-			self.Awake();
-		}
-	}
-
-	/// <summary>
-	/// 用来缓存数据
-	/// </summary>
-	public class DBCacheComponent : Component
-	{
-		public Dictionary<string, Dictionary<long, ComponentWithId>> cache = new Dictionary<string, Dictionary<long, ComponentWithId>>();
-
-		public const int taskCount = 32;
-		public List<DBTaskQueue> tasks = new List<DBTaskQueue>(taskCount);
-
-		public void Awake()
-		{
-			for (int i = 0; i < taskCount; ++i)
-			{
-				DBTaskQueue taskQueue = ComponentFactory.Create<DBTaskQueue>();
-				this.tasks.Add(taskQueue);
-			}
-		}
-
-		public ETTask<bool> Add(ComponentWithId component, string collectionName = "")
-		{
-			ETTaskCompletionSource<bool> tcs = new ETTaskCompletionSource<bool>();
-
-			if (string.IsNullOrEmpty(collectionName))
-			{
-				collectionName = component.GetType().Name;
-			}
-			DBSaveTask task = ComponentFactory.CreateWithId<DBSaveTask, ComponentWithId, string, ETTaskCompletionSource<bool>>(component.Id, component, collectionName, tcs);
-			this.tasks[(int)((ulong)task.Id % taskCount)].Add(task);
-
-			return tcs.Task;
-		}
-
-		public ETTask<bool> AddBatch(List<ComponentWithId> components, string collectionName)
-		{
-			ETTaskCompletionSource<bool> tcs = new ETTaskCompletionSource<bool>();
-			DBSaveBatchTask task = ComponentFactory.Create<DBSaveBatchTask, List<ComponentWithId>, string, ETTaskCompletionSource<bool>>(components, collectionName, tcs);
-			this.tasks[(int)((ulong)task.Id % taskCount)].Add(task);
-			return tcs.Task;
-		}
-
-		public void AddToCache(ComponentWithId component, string collectionName = "")
-		{
-			if (string.IsNullOrEmpty(collectionName))
-			{
-				collectionName = component.GetType().Name;
-			}
-			Dictionary<long, ComponentWithId> collection;
-			if (!this.cache.TryGetValue(collectionName, out collection))
-			{
-				collection = new Dictionary<long, ComponentWithId>();
-				this.cache.Add(collectionName, collection);
-			}
-			collection[component.Id] = component;
-		}
-
-		public ComponentWithId GetFromCache(string collectionName, long id)
-		{
-			Dictionary<long, ComponentWithId> d;
-			if (!this.cache.TryGetValue(collectionName, out d))
-			{
-				return null;
-			}
-			ComponentWithId result;
-			if (!d.TryGetValue(id, out result))
-			{
-				return null;
-			}
-			return result;
-		}
-
-		public void RemoveFromCache(string collectionName, long id)
-		{
-			Dictionary<long, ComponentWithId> d;
-			if (!this.cache.TryGetValue(collectionName, out d))
-			{
-				return;
-			}
-			d.Remove(id);
-		}
-
-		public ETTask<ComponentWithId> Get(string collectionName, long id)
-		{
-			ComponentWithId component = GetFromCache(collectionName, id);
-			if (component != null)
-			{
-				return ETTask.FromResult(component);
-			}
-
-			ETTaskCompletionSource<ComponentWithId> tcs = new ETTaskCompletionSource<ComponentWithId>();
-			DBQueryTask dbQueryTask = ComponentFactory.CreateWithId<DBQueryTask, string, ETTaskCompletionSource<ComponentWithId>>(id, collectionName, tcs);
-			this.tasks[(int)((ulong)id % taskCount)].Add(dbQueryTask);
-
-			return tcs.Task;
-		}
-
-		public ETTask<List<ComponentWithId>> GetBatch(string collectionName, List<long> idList)
-		{
-			List <ComponentWithId> components = new List<ComponentWithId>();
-			bool isAllInCache = true;
-			foreach (long id in idList)
-			{
-				ComponentWithId component = this.GetFromCache(collectionName, id);
-				if (component == null)
-				{
-					isAllInCache = false;
-					break;
-				}
-				components.Add(component);
-			}
-
-			if (isAllInCache)
-			{
-				return ETTask.FromResult(components);
-			}
-
-			ETTaskCompletionSource<List<ComponentWithId>> tcs = new ETTaskCompletionSource<List<ComponentWithId>>();
-			DBQueryBatchTask dbQueryBatchTask = ComponentFactory.Create<DBQueryBatchTask, List<long>, string, ETTaskCompletionSource<List<ComponentWithId>>>(idList, collectionName, tcs);
-			this.tasks[(int)((ulong)dbQueryBatchTask.Id % taskCount)].Add(dbQueryBatchTask);
-
-			return tcs.Task;
-		}
-		
-		public ETTask<List<ComponentWithId>> GetJson(string collectionName, string json)
-		{
-			ETTaskCompletionSource<List<ComponentWithId>> tcs = new ETTaskCompletionSource<List<ComponentWithId>>();
-			
-			DBQueryJsonTask dbQueryJsonTask = ComponentFactory.Create<DBQueryJsonTask, string, string, ETTaskCompletionSource<List<ComponentWithId>>>(collectionName, json, tcs);
-			this.tasks[(int)((ulong)dbQueryJsonTask.Id % taskCount)].Add(dbQueryJsonTask);
-
-			return tcs.Task;
-		}
-	}
-}

+ 65 - 5
Server/Model/Module/DB/DBComponent.cs

@@ -1,4 +1,5 @@
-using MongoDB.Driver;
+using System.Collections.Generic;
+using MongoDB.Driver;
 
 namespace ETModel
 {
@@ -12,24 +13,83 @@ namespace ETModel
 	}
 
 	/// <summary>
-	/// 连接mongodb
+	/// 用来缓存数据
 	/// </summary>
 	public class DBComponent : Component
 	{
 		public MongoClient mongoClient;
 		public IMongoDatabase database;
+		
+		public const int taskCount = 32;
+		public List<DBTaskQueue> tasks = new List<DBTaskQueue>(taskCount);
 
 		public void Awake()
 		{
-			DBConfig config = Game.Scene.GetComponent<StartConfigComponent>().StartConfig.GetComponent<DBConfig>();
+			DBConfig config = StartConfigComponent.Instance.StartConfig.GetComponent<DBConfig>();
 			string connectionString = config.ConnectionString;
 			mongoClient = new MongoClient(connectionString);
 			this.database = this.mongoClient.GetDatabase(config.DBName);
+			
+			for (int i = 0; i < taskCount; ++i)
+			{
+				DBTaskQueue taskQueue = ComponentFactory.Create<DBTaskQueue>();
+				this.tasks.Add(taskQueue);
+			}
 		}
-
+		
 		public IMongoCollection<ComponentWithId> GetCollection(string name)
 		{
 			return this.database.GetCollection<ComponentWithId>(name);
 		}
+
+		public ETTask Add(ComponentWithId component, string collectionName = "")
+		{
+			ETTaskCompletionSource tcs = new ETTaskCompletionSource();
+
+			if (string.IsNullOrEmpty(collectionName))
+			{
+				collectionName = component.GetType().Name;
+			}
+			DBSaveTask task = ComponentFactory.CreateWithId<DBSaveTask, ComponentWithId, string, ETTaskCompletionSource>(component.Id, component, collectionName, tcs);
+			this.tasks[(int)((ulong)task.Id % taskCount)].Add(task);
+
+			return tcs.Task;
+		}
+
+		public ETTask AddBatch(List<ComponentWithId> components, string collectionName)
+		{
+			ETTaskCompletionSource tcs = new ETTaskCompletionSource();
+			DBSaveBatchTask task = ComponentFactory.Create<DBSaveBatchTask, List<ComponentWithId>, string, ETTaskCompletionSource>(components, collectionName, tcs);
+			this.tasks[(int)((ulong)task.Id % taskCount)].Add(task);
+			return tcs.Task;
+		}
+
+		public ETTask<ComponentWithId> Get(string collectionName, long id)
+		{
+			ETTaskCompletionSource<ComponentWithId> tcs = new ETTaskCompletionSource<ComponentWithId>();
+			DBQueryTask dbQueryTask = ComponentFactory.CreateWithId<DBQueryTask, string, ETTaskCompletionSource<ComponentWithId>>(id, collectionName, tcs);
+			this.tasks[(int)((ulong)id % taskCount)].Add(dbQueryTask);
+
+			return tcs.Task;
+		}
+
+		public ETTask<List<ComponentWithId>> GetBatch(string collectionName, List<long> idList)
+		{
+			ETTaskCompletionSource<List<ComponentWithId>> tcs = new ETTaskCompletionSource<List<ComponentWithId>>();
+			DBQueryBatchTask dbQueryBatchTask = ComponentFactory.Create<DBQueryBatchTask, List<long>, string, ETTaskCompletionSource<List<ComponentWithId>>>(idList, collectionName, tcs);
+			this.tasks[(int)((ulong)dbQueryBatchTask.Id % taskCount)].Add(dbQueryBatchTask);
+
+			return tcs.Task;
+		}
+		
+		public ETTask<List<ComponentWithId>> GetJson(string collectionName, string json)
+		{
+			ETTaskCompletionSource<List<ComponentWithId>> tcs = new ETTaskCompletionSource<List<ComponentWithId>>();
+			
+			DBQueryJsonTask dbQueryJsonTask = ComponentFactory.Create<DBQueryJsonTask, string, string, ETTaskCompletionSource<List<ComponentWithId>>>(collectionName, json, tcs);
+			this.tasks[(int)((ulong)dbQueryJsonTask.Id % taskCount)].Add(dbQueryJsonTask);
+
+			return tcs.Task;
+		}
 	}
-}
+}

+ 2 - 7
Server/Model/Module/DB/DBQueryBatchTask.cs

@@ -25,7 +25,6 @@ namespace ETModel
 		
 		public override async ETTask Run()
 		{
-			DBCacheComponent dbCacheComponent = Game.Scene.GetComponent<DBCacheComponent>();
 			DBComponent dbComponent = Game.Scene.GetComponent<DBComponent>();
 			List<ComponentWithId> result = new List<ComponentWithId>();
 
@@ -34,12 +33,8 @@ namespace ETModel
 				// 执行查询数据库任务
 				foreach (long id in IdList)
 				{
-					ComponentWithId component = dbCacheComponent.GetFromCache(this.CollectionName, id);
-					if (component == null)
-					{
-						IAsyncCursor<ComponentWithId> cursor = await dbComponent.GetCollection(this.CollectionName).FindAsync((s) => s.Id == id);
-						component = await cursor.FirstOrDefaultAsync();
-					}
+					IAsyncCursor<ComponentWithId> cursor = await dbComponent.GetCollection(this.CollectionName).FindAsync((s) => s.Id == id);
+					ComponentWithId component = await cursor.FirstOrDefaultAsync();
 					
 					if (component == null)
 					{

+ 1 - 9
Server/Model/Module/DB/DBQueryTask.cs

@@ -21,20 +21,12 @@ namespace ETModel
 
 		public override async ETTask Run()
 		{
-			DBCacheComponent dbCacheComponent = Game.Scene.GetComponent<DBCacheComponent>();
 			DBComponent dbComponent = Game.Scene.GetComponent<DBComponent>();
-			// 执行查询前先看看cache中是否已经存在
-			ComponentWithId component = dbCacheComponent.GetFromCache(this.CollectionName, this.Id);
-			if (component != null)
-			{
-				this.Tcs.SetResult(component);
-				return;
-			}
 			try
 			{
 				// 执行查询数据库任务
 				IAsyncCursor<ComponentWithId> cursor = await dbComponent.GetCollection(this.CollectionName).FindAsync((s) => s.Id == this.Id);
-				component = await cursor.FirstOrDefaultAsync();
+				ComponentWithId component = await cursor.FirstOrDefaultAsync();
 				this.Tcs.SetResult(component);
 			}
 			catch (Exception e)

+ 4 - 4
Server/Model/Module/DB/DBSaveBatchTask.cs

@@ -6,9 +6,9 @@ using MongoDB.Driver;
 namespace ETModel
 {
 	[ObjectSystem]
-	public class DbSaveBatchTaskSystem : AwakeSystem<DBSaveBatchTask, List<ComponentWithId>, string, ETTaskCompletionSource<bool>>
+	public class DbSaveBatchTaskSystem : AwakeSystem<DBSaveBatchTask, List<ComponentWithId>, string, ETTaskCompletionSource>
 	{
-		public override void Awake(DBSaveBatchTask self, List<ComponentWithId> components, string collectionName, ETTaskCompletionSource<bool> tcs)
+		public override void Awake(DBSaveBatchTask self, List<ComponentWithId> components, string collectionName, ETTaskCompletionSource tcs)
 		{
 			self.Components = components;
 			self.CollectionName = collectionName;
@@ -22,7 +22,7 @@ namespace ETModel
 
 		public List<ComponentWithId> Components;
 
-		public ETTaskCompletionSource<bool> Tcs;
+		public ETTaskCompletionSource Tcs;
 	
 		public override async ETTask Run()
 		{
@@ -46,7 +46,7 @@ namespace ETModel
 					this.Tcs.SetException(new Exception($"保存数据失败! {CollectionName} {this.Components.ListToString()}", e));
 				}
 			}
-			this.Tcs.SetResult(true);
+			this.Tcs.SetResult();
 		}
 	}
 }

+ 4 - 4
Server/Model/Module/DB/DBSaveTask.cs

@@ -5,9 +5,9 @@ namespace ETModel
 {
 
 	[ObjectSystem]
-	public class DbSaveTaskAwakeSystem : AwakeSystem<DBSaveTask, ComponentWithId, string, ETTaskCompletionSource<bool>>
+	public class DbSaveTaskAwakeSystem : AwakeSystem<DBSaveTask, ComponentWithId, string, ETTaskCompletionSource>
 	{
-		public override void Awake(DBSaveTask self, ComponentWithId component, string collectionName, ETTaskCompletionSource<bool> tcs)
+		public override void Awake(DBSaveTask self, ComponentWithId component, string collectionName, ETTaskCompletionSource tcs)
 		{
 			self.Component = component;
 			self.CollectionName = collectionName;
@@ -21,7 +21,7 @@ namespace ETModel
 
 		public string CollectionName { get; set; }
 
-		public ETTaskCompletionSource<bool> Tcs;
+		public ETTaskCompletionSource Tcs;
 
 		public override async ETTask Run()
 		{
@@ -31,7 +31,7 @@ namespace ETModel
 			{
 				// 执行保存数据库任务
 				await dbComponent.GetCollection(this.CollectionName).ReplaceOneAsync(s => s.Id == this.Component.Id, this.Component, new UpdateOptions {IsUpsert = true});
-				this.Tcs.SetResult(true);
+				this.Tcs.SetResult();
 			}
 			catch (Exception e)
 			{

+ 1 - 8
Server/Model/Module/Message/InnerMessage.cs

@@ -1,3 +1,4 @@
+using ETModel;
 using System.Collections.Generic;
 namespace ETModel
 {
@@ -93,8 +94,6 @@ namespace ETModel
 	{
 		public int RpcId { get; set; }
 
-		public bool NeedCache { get; set; }
-
 		public string CollectionName { get; set; }
 
 		public ComponentWithId Component { get; set; }
@@ -117,8 +116,6 @@ namespace ETModel
 	{
 		public int RpcId { get; set; }
 
-		public bool NeedCache { get; set; }
-
 		public string CollectionName { get; set; }
 
 		public List<ComponentWithId> Components = new List<ComponentWithId>();
@@ -145,8 +142,6 @@ namespace ETModel
 
 		public string CollectionName { get; set; }
 
-		public bool NeedCache { get; set; }
-
 	}
 
 	[Message(InnerOpcode.DBQueryResponse)]
@@ -171,8 +166,6 @@ namespace ETModel
 
 		public List<long> IdList = new List<long>();
 
-		public bool NeedCache { get; set; }
-
 	}
 
 	[Message(InnerOpcode.DBQueryBatchResponse)]

+ 6 - 7
Unity/Assets/Model/Component/SceneChangeComponent.cs

@@ -1,5 +1,4 @@
-using System.Threading.Tasks;
-using UnityEngine;
+using UnityEngine;
 using UnityEngine.SceneManagement;
 
 namespace ETModel
@@ -11,7 +10,7 @@ namespace ETModel
 		{
 			if (self.loadMapOperation.isDone)
 			{
-				self.tcs.SetResult(true);
+				self.tcs.SetResult();
 			}
 		}
 	}
@@ -19,13 +18,13 @@ namespace ETModel
 	public class SceneChangeComponent: Component
 	{
 		public AsyncOperation loadMapOperation;
-		public ETTaskCompletionSource<bool> tcs;
+		public ETTaskCompletionSource tcs;
 	    public float deltaTime;
 	    public int lastProgress = 0;
 
-		public ETTask<bool> ChangeSceneAsync(string sceneName)
+		public ETTask ChangeSceneAsync(string sceneName)
 		{
-			this.tcs = new ETTaskCompletionSource<bool>();
+			this.tcs = new ETTaskCompletionSource();
 			// 加载map
 			this.loadMapOperation = SceneManager.LoadSceneAsync(sceneName);
 			return this.tcs.Task;
@@ -45,7 +44,7 @@ namespace ETModel
 
 		public void Finish()
 		{
-			this.tcs.SetResult(true);
+			this.tcs.SetResult();
 		}
 
 		public override void Dispose()

+ 5 - 5
Unity/Assets/Model/Entity/UnityWebRequestAsync.cs

@@ -21,7 +21,7 @@ namespace ETModel
 
 		public bool isCancel;
 
-		public ETTaskCompletionSource<bool> tcs;
+		public ETTaskCompletionSource tcs;
 		
 		public override void Dispose()
 		{
@@ -65,7 +65,7 @@ namespace ETModel
 		{
 			if (this.isCancel)
 			{
-				this.tcs.SetResult(false);
+				this.tcs.SetException(new Exception($"request error: {this.Request.error}"));
 				return;
 			}
 			
@@ -79,12 +79,12 @@ namespace ETModel
 				return;
 			}
 
-			this.tcs.SetResult(true);
+			this.tcs.SetResult();
 		}
 
-		public ETTask<bool> DownloadAsync(string url)
+		public ETTask DownloadAsync(string url)
 		{
-			this.tcs = new ETTaskCompletionSource<bool>();
+			this.tcs = new ETTaskCompletionSource();
 			
 			url = url.Replace(" ", "%20");
 			this.Request = UnityWebRequest.Get(url);

+ 5 - 5
Unity/Assets/Model/Module/AssetsBundle/AssetsLoaderAsync.cs

@@ -28,7 +28,7 @@ namespace ETModel
 
 		private AssetBundleRequest request;
 
-		private ETTaskCompletionSource<bool> tcs;
+		private ETTaskCompletionSource tcs;
 
 		public void Awake(AssetBundle ab)
 		{
@@ -42,8 +42,8 @@ namespace ETModel
 				return;
 			}
 
-			ETTaskCompletionSource<bool> t = tcs;
-			t.SetResult(true);
+			ETTaskCompletionSource t = tcs;
+			t.SetResult();
 		}
 
 		public override void Dispose()
@@ -64,9 +64,9 @@ namespace ETModel
 			return this.request.allAssets;
 		}
 
-		private ETTask<bool> InnerLoadAllAssetsAsync()
+		private ETTask InnerLoadAllAssetsAsync()
 		{
-			this.tcs = new ETTaskCompletionSource<bool>();
+			this.tcs = new ETTaskCompletionSource();
 			this.request = assetBundle.LoadAllAssetsAsync();
 			return this.tcs.Task;
 		}

+ 1 - 3
Unity/Assets/Model/Module/Message/NetOuterComponentSystem.cs

@@ -1,6 +1,4 @@
-using System.Collections.Generic;
-using System.Net;
-using ETModel;
+using ETModel;
 
 namespace ETHotfix
 {

+ 1 - 0
Unity/Assets/Model/Module/Message/OuterOpcode.cs

@@ -1,3 +1,4 @@
+using ETModel;
 namespace ETModel
 {
 	[Message(OuterOpcode.Actor_Test)]