Skip to content
Browse files

[WebService] Lazy init Build so that the DB is only hit when necessar…

…y and don't create a new list if no-one is listening.
  • Loading branch information...
1 parent e2b9b29 commit 567d13e8e65746e522abb1097dda47e6fbb14367 @garuma garuma committed
Showing with 25 additions and 15 deletions.
  1. +25 −15 MonkeyWrench.Web.WebService/WebNotification.cs
View
40 MonkeyWrench.Web.WebService/WebNotification.cs
@@ -72,6 +72,30 @@ public void Process (Build aBuild)
public static void BroadcastBuildNotification (DBWork work, DBRevisionWork revisionWork)
{
+ BroadcastBuildNotification (new Lazy<Build> (() => GetBuildFromDBItems (work, revisionWork)));
+ }
+
+ public static void BroadcastBuildNotification (Build aBuild)
+ {
+ BroadcastBuildNotification (new Lazy<Build> (() => aBuild));
+ }
+
+ static void BroadcastBuildNotification (Lazy<Build> build)
+ {
+ List<ObserverSlot> currentSlots = null;
+ lock (slots) {
+ if (slots.Count == 0)
+ return;
+ currentSlots = new List<ObserverSlot> (slots);
+ slots.Clear ();
+ }
+
+ foreach (var slot in currentSlots)
+ slot.Process (build.Value);
+ }
+
+ static Build GetBuildFromDBItems (DBWork work, DBRevisionWork revisionWork)
+ {
DBRevision revision;
DBLane lane, parentLane;
DBHost host;
@@ -86,7 +110,7 @@ public static void BroadcastBuildNotification (DBWork work, DBRevisionWork revis
var url = Configuration.GetWebSiteUrl ();
url += string.Format ("/ViewLane.aspx?lane_id={0}&host_id={1}&revision_id={2}", lane.id, host.id, revision.id);
- var build = new Build {
+ return new Build {
Commit = revision.revision,
CommitId = revision.id,
Date = revisionWork.completed ? revisionWork.endtime : revision.date,
@@ -97,8 +121,6 @@ public static void BroadcastBuildNotification (DBWork work, DBRevisionWork revis
BuildBot = host.host,
Url = url
};
-
- BroadcastBuildNotification (build);
}
static DBLane GetTopMostParent (DBLane forLane, DB db)
@@ -109,18 +131,6 @@ static DBLane GetTopMostParent (DBLane forLane, DB db)
return parent;
}
- public static void BroadcastBuildNotification (Build aBuild)
- {
- List<ObserverSlot> currentSlots = null;
- lock (slots) {
- currentSlots = new List<ObserverSlot> (slots);
- slots.Clear ();
- }
-
- foreach (var slot in currentSlots)
- slot.Process (aBuild);
- }
-
public IAsyncResult BeginProcessRequest (HttpContext context, AsyncCallback cb, object extraData)
{
var login = CreateLogin (context.Request);

0 comments on commit 567d13e

Please sign in to comment.
Something went wrong with that request. Please try again.