Skip to content

Commit 88f1113

Browse files
committed
PR 30: Updated code to try and improve performance. +semver: minor
- Updated code to try and improve performance. +semver: minor
1 parent dade0e8 commit 88f1113

File tree

5 files changed

+43
-13
lines changed

5 files changed

+43
-13
lines changed

TfsWitMigrator.Core/ComponentContext/TfsQueryContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public WorkItemCollection Execute()
4545
{ "QueryTime", queryTimer.ElapsedMilliseconds },
4646
{ "QueryCount", wc.Count }
4747
});
48-
Trace.TraceInformation(string.Format(" Query Complete: found {0} work items ", wc.Count));
48+
Trace.TraceInformation(string.Format(" Query Complete: found {0} work items in {1}ms ", wc.Count, queryTimer.ElapsedMilliseconds));
4949

5050
}
5151
catch (Exception ex)

TfsWitMigrator.Core/ComponentContext/WorkItemStoreContext.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,14 @@ public WorkItem FindReflectedWorkItem(WorkItem workItemToFind, string reflectedW
9393
}
9494
}
9595
if (found == null) { found = FindReflectedWorkItemByReflectedWorkItemId(ReflectedWorkItemId, reflectedWotkItemIdField); }
96-
if (found == null) { found = FindReflectedWorkItemByMigrationRef(ReflectedWorkItemId); }
97-
//if (found == null) { found = FindReflectedWorkItemByTitle(workItemToFind.Title); }
96+
if (!workItemToFind.Fields.Contains(reflectedWotkItemIdField))
97+
{
98+
if (found == null) { found = FindReflectedWorkItemByMigrationRef(ReflectedWorkItemId); } // Too slow!
99+
//if (found == null) { found = FindReflectedWorkItemByTitle(workItemToFind.Title); }
100+
}
98101
if (found != null)
99102
{
100-
foundWis.Add(workItemToFind.Id, found);
103+
foundWis.Add(workItemToFind.Id, found); /// TODO MENORY LEEK! LEAK
101104
}
102105

103106
return found;

TfsWitMigrator.Core/MigrationContext/WorkItemMigrationContext.cs

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,14 @@ private static WorkItem CreateAndPopulateWorkItem(WorkItem oldWi, Project destPr
170170

171171

172172
// WorkItem newwit = oldWi.Copy(destProject.WorkItemTypes[destType]);
173+
var NewWorkItemstartTime = DateTime.UtcNow;
174+
Stopwatch NewWorkItemTimer = new Stopwatch();
173175
WorkItem newwit = destProject.WorkItemTypes[destType].NewWorkItem();
176+
NewWorkItemTimer.Stop();
177+
Telemetry.Current.TrackDependency("TeamService", "NewWorkItem", NewWorkItemstartTime, NewWorkItemTimer.Elapsed, true);
178+
Trace.WriteLine(string.Format("Dependnacy: {0} - {1} - {2} - {3} - {4}", "TeamService", "NewWorkItem", NewWorkItemstartTime, NewWorkItemTimer.Elapsed, true));
179+
180+
174181
newwit.Title = oldWi.Title;
175182
newwit.State = oldWi.State;
176183
switch (newwit.State)
@@ -253,25 +260,42 @@ private static string ReplaceFirstOccurence(string wordToReplace, string replace
253260
}
254261

255262

256-
private static void BuildFieldTable(WorkItem oldWi, StringBuilder history)
263+
private static void BuildFieldTable(WorkItem oldWi, StringBuilder history, bool useHTML = false)
257264
{
258-
history.Append("<p>&nbsp;</p>");
259-
history.Append("<table border='1' cellpadding='2' style='width:100%;border-color:#C0C0C0;'><tr><td><b>Field</b></td><td><b>Value</b></td></tr>");
265+
if (useHTML) {
266+
history.Append("<p>&nbsp;</p>");
267+
history.Append("<table border='1' cellpadding='2' style='width:100%;border-color:#C0C0C0;'><tr><td><b>Field</b></td><td><b>Value</b></td></tr>");
268+
}
260269
foreach (Field f in oldWi.Fields)
261270
{
262271
if (f.Value == null)
263272
{
264-
history.AppendFormat("<tr><td style='text-align:right;white-space:nowrap;'><b>{0}</b></td><td>n/a</td></tr>", f.Name);
265-
273+
if (useHTML)
274+
{
275+
history.AppendFormat("<tr><td style='text-align:right;white-space:nowrap;'><b>{0}</b></td><td>n/a</td></tr>", f.Name);
276+
} else
277+
{
278+
history.AppendLine(string.Format("{0}: null", f.Name));
279+
}
266280
}
267281
else
268282
{
269-
history.AppendFormat("<tr><td style='text-align:right;white-space:nowrap;'><b>{0}</b></td><td style='width:100%'>{1}</td></tr>", f.Name, f.Value.ToString());
283+
if (useHTML)
284+
{
285+
history.AppendFormat("<tr><td style='text-align:right;white-space:nowrap;'><b>{0}</b></td><td style='width:100%'>{1}</td></tr>", f.Name, f.Value.ToString());
286+
287+
}else
288+
{
289+
history.AppendLine(string.Format("{0}: {1}", f.Name, f.Value.ToString()));
290+
}
270291
}
271292

272293
}
273-
history.Append("</table>");
274-
history.Append("<p>&nbsp;</p>");
294+
if (useHTML)
295+
{
296+
history.Append("</table>");
297+
history.Append("<p>&nbsp;</p>");
298+
}
275299
}
276300

277301
private static void BuildCommentTable(WorkItem oldWi, StringBuilder history)

TfsWitMigrator.Core/MigrationEngine.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class MigrationEngine
1919
ITeamProjectContext source;
2020
ITeamProjectContext target;
2121
string reflectedWorkItemIdFieldName = "TfsMigrationTool.ReflectedWorkItemId";
22+
2223

2324
public Dictionary<string, IWitdMapper> WorkItemTypeDefinitions
2425
{

TfsWitMigrator.Core/Telemetry.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ public static TelemetryClient Current { get {
2424

2525
public static void InitiliseTelemetry()
2626
{
27-
Trace.Listeners.Add(new ApplicationInsightsTraceListener(applicationInsightsKey));
27+
// Performance? Trace.Listeners.Add(new ApplicationInsightsTraceListener(applicationInsightsKey));
2828
Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.Active.InstrumentationKey = applicationInsightsKey;
2929
telemetryClient = new TelemetryClient();
3030
telemetryClient.InstrumentationKey = applicationInsightsKey;
3131
telemetryClient.Context.User.Id = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
3232
telemetryClient.Context.Session.Id = Guid.NewGuid().ToString();
33+
Trace.WriteLine(string.Format("SessionID: {0}", telemetryClient.Context.Session.Id));
34+
3335
}
3436
}
3537
}

0 commit comments

Comments
 (0)