Optimize the LocalPriceCache by adding a method to PricingDA
This commit is contained in:
@@ -285,6 +285,50 @@ namespace MarketData.DataAccess
|
||||
if(null!=sqlConnection) sqlConnection.Close();
|
||||
}
|
||||
}
|
||||
|
||||
public static Dictionary<String,DateTime> GetLatestDates(List<String> symbols)
|
||||
{
|
||||
MySqlConnection sqlConnection = null;
|
||||
MySqlDataReader sqlDataReader = null;
|
||||
MySqlCommand sqlCommand = null;
|
||||
String strQuery = null;
|
||||
Dictionary<String,DateTime> latestDates = new Dictionary<String,DateTime>();
|
||||
|
||||
try
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sqlConnection = SqlUtils.CreateMySqlConnection(MainDataSource.Instance.LocateDataSource("market_data"));
|
||||
sb.Append(" select symbol, max(date) as date ");
|
||||
sb.Append(" from prices where symbol in").Append(SqlUtils.CreateInClause(symbols));
|
||||
sb.Append(" group by symbol order by symbol");
|
||||
strQuery = sb.ToString();
|
||||
sqlCommand = new MySqlCommand(strQuery, sqlConnection);
|
||||
sqlCommand.CommandTimeout = SqlUtils.COMMAND_TIMEOUT;
|
||||
sqlDataReader = sqlCommand.ExecuteReader();
|
||||
while (sqlDataReader.Read())
|
||||
{
|
||||
if(sqlDataReader.IsDBNull(0) || sqlDataReader.IsDBNull(1))continue;
|
||||
String symbol = sqlDataReader.GetString(0);
|
||||
DateTime latestDate = sqlDataReader.GetDateTime(1);
|
||||
if(latestDates.ContainsKey(symbol))continue;
|
||||
latestDates.Add(symbol, latestDate);
|
||||
}
|
||||
return latestDates;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,exception);
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Query was {0}",strQuery));
|
||||
return latestDates;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (null != sqlCommand) sqlCommand.Dispose();
|
||||
if (null != sqlDataReader) sqlDataReader.Close();
|
||||
if (null != sqlConnection) sqlConnection.Close();
|
||||
}
|
||||
}
|
||||
|
||||
public static DateTime GetLatestDate(List<String> symbols)
|
||||
{
|
||||
MySqlConnection sqlConnection = null;
|
||||
|
||||
Reference in New Issue
Block a user