Skip to content

Commit

Permalink
Worked on improving the performance of the FirstPointCom ingest and r…
Browse files Browse the repository at this point in the history
…educing memory consumption.
  • Loading branch information
uncheckederror committed Nov 1, 2024
1 parent cafcffc commit fbd295a
Show file tree
Hide file tree
Showing 21 changed files with 604 additions and 605 deletions.
10 changes: 5 additions & 5 deletions FirstCom/Connected Services/ServiceReference1/Reference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public interface DIDManagementSoap
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.1.0")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="https://api.1pcom.net/")]
public partial class QueryResult
public partial struct QueryResult
{

private int codeField;
Expand Down Expand Up @@ -413,7 +413,7 @@ public QueryResult queryresult
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.1.0")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="https://api.1pcom.net/")]
public partial class DIDOrderInfo
public partial struct DIDOrderInfo
{

private string dIDField;
Expand Down Expand Up @@ -549,7 +549,7 @@ public QueryResult QueryResult
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.1.0")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="https://api.1pcom.net/")]
public partial class DIDOrderInfoArray
public partial struct DIDOrderInfoArray
{

private DIDOrderInfo[] dIDOrderField;
Expand Down Expand Up @@ -589,7 +589,7 @@ public QueryResult queryresult
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.1.0")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="https://api.1pcom.net/")]
public partial class DIDOrderQuery
public partial struct DIDOrderQuery
{

private string rateCenterField;
Expand Down Expand Up @@ -661,7 +661,7 @@ public string DID
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.1.0")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="https://api.1pcom.net/")]
public partial class Credentials
public partial struct Credentials
{

private string usernameField;
Expand Down
5 changes: 2 additions & 3 deletions FirstCom/FirstCom/FirstCom.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

using NumberSearch.DataAccess;
using NumberSearch.DataAccess.Models;

using Serilog;

Expand All @@ -25,7 +24,7 @@ public static async Task<PhoneNumber[]> GetValidNumbersByNPAAsync(string usernam
{
try
{
numbers.AddRange(await NpaNxxFirstPointCom.GetAsync(code.ToString(), string.Empty, string.Empty, username, password));
numbers.AddRange(await NpaNxxFirstPointCom.GetAsync(code.ToString().AsMemory(), string.Empty.AsMemory(), string.Empty.AsMemory(), username.AsMemory(), password.AsMemory()));
Log.Information($"[FirstPointCom] Found {numbers.Count} Phone Numbers");
}
catch (Exception ex)
Expand Down
72 changes: 31 additions & 41 deletions FirstCom/FirstCom/NpaNxxFirstPointCom.cs
Original file line number Diff line number Diff line change
@@ -1,82 +1,72 @@
using NumberSearch.DataAccess;
using NumberSearch.DataAccess.Models;

using Serilog;

using ServiceReference1;

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Threading.Tasks;

namespace FirstCom
{
public sealed class NpaNxxFirstPointCom
{
public static async Task<IEnumerable<PhoneNumber>> GetAsync(string npa, string nxx, string did, string username, string password)
public static async Task<PhoneNumber[]> GetAsync(ReadOnlyMemory<char> npa, ReadOnlyMemory<char> nxx, ReadOnlyMemory<char> did, ReadOnlyMemory<char> username, ReadOnlyMemory<char> password)
{
var Auth = new Credentials
{
Username = username,
Password = password
Username = username.ToString(),
Password = password.ToString()
};
var DIDSearch = new DIDOrderQuery
{
DID = did,
NPA = npa,
NXX = nxx,
DID = did.ToString(),
NPA = npa.ToString(),
NXX = nxx.ToString(),
RateCenter = string.Empty
};
// Limited to 100 results at the moment.
var ReturnAmount = 100;
// Limited to 100 results at the moment. There's no way to offset the results to get the complete list of numbers, so we won't bother.
int ReturnAmount = 100;

using var client = new DIDManagementSoapClient(DIDManagementSoapClient.EndpointConfiguration.DIDManagementSoap);

var list = new List<PhoneNumber>();
bool moreToQuery = true;

while (moreToQuery)
{
var result = await client.DIDInventorySearchAsync(Auth, DIDSearch, ReturnAmount).ConfigureAwait(false);
var result = await client.DIDInventorySearchAsync(Auth, DIDSearch, ReturnAmount).ConfigureAwait(false);

foreach (var item in result.DIDOrder)
foreach (var item in result.DIDOrder)
{
if (item.DID.StartsWith('1'))
{
if (item.DID.StartsWith('1'))
{
var checkParse = PhoneNumbersNA.PhoneNumber.TryParse(item.DID[1..], out var phoneNumber);
var checkParse = PhoneNumbersNA.PhoneNumber.TryParse(item.DID[1..].AsSpan(), out var phoneNumber);

if (checkParse)
{
list.Add(new PhoneNumber
{
NPA = phoneNumber.NPA,
NXX = phoneNumber.NXX,
XXXX = phoneNumber.XXXX,
DialedNumber = phoneNumber.DialedNumber,
City = "Unknown City",
State = "Unknown State",
DateIngested = DateTime.Now,
IngestedFrom = "FirstPointCom"
});
}
else
if (checkParse)
{
list.Add(new PhoneNumber
{
Log.Error($"[FirstCom] This number failed to parse {item.DID}");
}
NPA = phoneNumber.NPA,
NXX = phoneNumber.NXX,
XXXX = phoneNumber.XXXX,
DialedNumber = phoneNumber.DialedNumber,
City = "Unknown City",
State = "Unknown State",
DateIngested = DateTime.Now,
IngestedFrom = "FirstPointCom"
});
}
else
{
Log.Error($"[FirstCom] This number did not start with a 1: {item.DID}");
Log.Error($"[FirstCom] This number failed to parse {item.DID}");
}
}

// Break the loop.
if (result.DIDOrder.Length is not 100)
else
{
moreToQuery = false;
Log.Error($"[FirstCom] This number did not start with a 1: {item.DID}");
}
}

return list;
return [..list];
}
}
}
2 changes: 2 additions & 0 deletions NumberSearch.DataAccess/BulkVS/OrderTn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

using Newtonsoft.Json;

using NumberSearch.DataAccess.Models;

using Serilog;

using System;
Expand Down
2 changes: 2 additions & 0 deletions NumberSearch.DataAccess/BulkVS/TnRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

using Newtonsoft.Json;

using NumberSearch.DataAccess.Models;

using Serilog;

using System;
Expand Down
10 changes: 4 additions & 6 deletions NumberSearch.DataAccess/LCGuide/RateCenterLookup.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
using Flurl.Http;

using System;
using System.Threading.Tasks;

namespace NumberSearch.DataAccess.LCGuide
{
public class RateCenterLookup
public readonly record struct RateCenterLookup(ReadOnlyMemory<char> RateCenter, ReadOnlyMemory<char> Region)
{
public string RateCenter { get; set; } = string.Empty;
public string Region { get; set; } = string.Empty;

public static async Task<RateCenterLookup> GetAsync(string npa, string nxx)
public static async Task<RateCenterLookup> GetAsync(ReadOnlyMemory<char> npa, ReadOnlyMemory<char> nxx)
{
string baseUrl = "https://localcallingguide.com/xmlprefix.php?";
string npaParameter = $"npa={npa}";
Expand All @@ -28,7 +26,7 @@ public static async Task<RateCenterLookup> GetAsync(string npa, string nxx)
var regionEnd = result.IndexOf("</region>");
var regionText = result[regionStart..regionEnd];

return new RateCenterLookup { RateCenter = rateCenterText, Region = regionText };
return new RateCenterLookup(rateCenterText.AsMemory(), regionText.AsMemory());
}
else
{
Expand Down
Loading

0 comments on commit fbd295a

Please sign in to comment.