Ignore:
Timestamp:
03/05/15 17:09:10 (6 years ago)
Author:
ascheibe
Message:

#2353

  • improved performance of status page
  • fixed code formatting and usings
  • simplified some expressions
Location:
trunk/sources/HeuristicLab.Services.Hive/3.3
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Services.Hive/3.3/HiveDao.cs

    r12012 r12146  
    869869    }
    870870
    871     public Dictionary<Guid, int> GetWaitingTasksByUser() {
    872       using (var db = CreateContext()) {
    873         var waitingTasksByUser = from task in db.Tasks
    874                                  where task.State == TaskState.Waiting
    875                                  group task by task.Job.OwnerUserId into g
    876                                  select new { UserId = g.Key, UsedCores = g.Count() };
    877         return waitingTasksByUser.ToDictionary(x => x.UserId, x => x.UsedCores);
    878       }
    879     }
    880 
    881871    public Dictionary<Guid, int> GetWaitingTasksByUserForResources(List<Guid> resourceIds) {
    882872      using (var db = CreateContext()) {
     
    886876                                 select new { UserId = g.Key, UsedCores = g.Count() };
    887877        return waitingTasksByUser.ToDictionary(x => x.UserId, x => x.UsedCores);
    888       }
    889     }
    890 
    891     public Dictionary<Guid, int> GetCalculatingTasksByUser() {
    892       using (var db = CreateContext()) {
    893         var calculatingTasksByUser = from task in db.Tasks
    894                                      where task.State == TaskState.Calculating
    895                                      group task by task.Job.OwnerUserId into g
    896                                      select new { UserId = g.Key, UsedCores = g.Count() };
    897         return calculatingTasksByUser.ToDictionary(x => x.UserId, x => x.UsedCores);
    898878      }
    899879    }
  • trunk/sources/HeuristicLab.Services.Hive/3.3/Interfaces/IHiveDao.cs

    r12012 r12146  
    150150
    151151    #region Statistics Methods
    152     Dictionary<Guid, int> GetWaitingTasksByUser();
    153152    Dictionary<Guid, int> GetWaitingTasksByUserForResources(List<Guid> resourceIds);
    154     Dictionary<Guid, int> GetCalculatingTasksByUser();
    155153    Dictionary<Guid, int> GetCalculatingTasksByUserForResources(List<Guid> resourceIds);
    156154    DT.Statistics GetStatistic(Guid id);
  • trunk/sources/HeuristicLab.Services.Hive/3.3/Interfaces/IOptimizedHiveDao.cs

    r12012 r12146  
    6565    IEnumerable<Guid> GetAssignedResourceIds(Guid jobId);
    6666    #endregion
     67
     68    #region Website Methods
     69
     70    IEnumerable<Guid> GetAllResourceIds();
     71
     72    int GetNumberOfWaitingTasks();
     73
     74    Dictionary<Guid, int> GetCalculatingTasksByUser();
     75
     76    Dictionary<Guid, int> GetWaitingTasksByUser();
     77
     78    #endregion
    6779  }
    6880}
  • trunk/sources/HeuristicLab.Services.Hive/3.3/OptimizedHiveDao.cs

    r12012 r12146  
    245245    );
    246246    #endregion
     247
     248
     249    #region Website Methods
     250    private const string GetAllResourceIdsString = @"SELECT ResourceId FROM [Resource]";
     251    public IEnumerable<Guid> GetAllResourceIds() {
     252      return Db.ExecuteQuery<Guid>(GetAllResourceIdsString);
     253    }
     254
     255    private const string GetNumberOfWaitingTasksString = @"SELECT COUNT(TaskId)
     256                                                           FROM [Task]
     257                                                           WHERE TaskState LIKE 'Waiting'";
     258    public int GetNumberOfWaitingTasks() {
     259      return Db.ExecuteQuery<int>(GetNumberOfWaitingTasksString).Single();
     260    }
     261
     262    private class UserTasks {
     263      public Guid OwnerUserId;
     264      public int Count;
     265    }
     266
     267    private const string GetCalculatingTasksByUserString = @"SELECT Job.OwnerUserId, COUNT(Task.TaskId) as Count
     268                                                             FROM Task, Job
     269                                                             WHERE TaskState LIKE 'Calculating' AND Task.JobId = Job.JobId
     270                                                             GROUP BY Job.OwnerUserId";
     271
     272    public Dictionary<Guid, int> GetCalculatingTasksByUser() {
     273      var result = Db.ExecuteQuery<UserTasks>(GetCalculatingTasksByUserString);
     274      Dictionary<Guid, int> lst = new Dictionary<Guid, int>();
     275
     276      foreach (var userTask in result) {
     277        lst.Add(userTask.OwnerUserId, userTask.Count);
     278      }
     279      return lst;
     280    }
     281
     282    private const string GetWaitingTasksByUserString = @"SELECT Job.OwnerUserId, COUNT(Task.TaskId) as Count
     283                                                         FROM Task, Job
     284                                                         WHERE TaskState LIKE 'Waiting' AND Task.JobId = Job.JobId
     285                                                         GROUP BY Job.OwnerUserId";
     286
     287    public Dictionary<Guid, int> GetWaitingTasksByUser() {
     288      var result = Db.ExecuteQuery<UserTasks>(GetWaitingTasksByUserString);
     289      Dictionary<Guid, int> lst = new Dictionary<Guid, int>();
     290
     291      foreach (var userTask in result) {
     292        lst.Add(userTask.OwnerUserId, userTask.Count);
     293      }
     294      return lst;
     295    }
     296    #endregion
    247297  }
    248298}
Note: See TracChangeset for help on using the changeset viewer.