public object Get(SqlServerQueriesRequest request) { using (var db = dbFactory.OpenDbConnection()) { var worldCount = Math.Max(1, Math.Min(500, (int)request.queries)); // limit queries to be between 1 and 500 iterations return(new HttpResult(db.GetRandomWorlds(worldCount, new Random()), ContentType.Json)); } }
public object Get(SqlServerQueriesRequest request) { // limit queries to be between 1 and 500 iterations var worldCount = Math.Max(1, Math.Min(500, (int)request.queries)); // concurrently create a list of random world ids to retrieve var ids = new List <int>(); Parallel.For(0, worldCount, i => { lock (ids) { ids.Add(SafeRandom.Instance.Next(0, 10000) + 1); } }); // retrieve worlds associated with ids using (var db = dbFactory.OpenDbConnection()) { return(db.GetWorlds(ids)); } }