QueryService.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System.Threading.Tasks;
  2. using Benchmarks.Data;
  3. using EasyRpc.Abstractions.Path;
  4. using EasyRpc.Abstractions.Services;
  5. namespace Benchmarks.Services
  6. {
  7. [SharedService]
  8. public class QueryService
  9. {
  10. private IRawDb _rawDb;
  11. public QueryService(IRawDb rawDb)
  12. {
  13. _rawDb = rawDb;
  14. }
  15. [GetMethod("/db")]
  16. public Task<World> Single()
  17. {
  18. return _rawDb.LoadSingleQueryRow();
  19. }
  20. [GetMethod("/queries/{count}")]
  21. public Task<World[]> Multiple(int count = 1)
  22. {
  23. if(count < 1 )
  24. {
  25. count = 1;
  26. }
  27. if(count > 500)
  28. {
  29. count = 500;
  30. }
  31. return _rawDb.LoadMultipleQueriesRows(count);
  32. }
  33. [GetMethod("/updates/{count}")]
  34. public Task<World[]> Updates(int count = 1)
  35. {
  36. if(count < 1 )
  37. {
  38. count = 1;
  39. }
  40. if(count > 500)
  41. {
  42. count = 500;
  43. }
  44. return _rawDb.LoadMultipleUpdatesRows(count);
  45. }
  46. [GetMethod("/cached-worlds/{count}")]
  47. public Task<World[]> CachedWorlds(int count = 1)
  48. {
  49. if(count < 1 )
  50. {
  51. count = 1;
  52. }
  53. if(count > 500)
  54. {
  55. count = 500;
  56. }
  57. return _rawDb.LoadCachedQueries(count);
  58. }
  59. }
  60. }