Skip to content

Commit 1cd4d38

Browse files
committed
Cleaning useless code. Removing unused columns in query. Issue dotnet/extensions#1268
\n\nCommit migrated from dotnet/extensions@8bafa5f
1 parent f1e6e71 commit 1cd4d38

File tree

4 files changed

+2
-80
lines changed

4 files changed

+2
-80
lines changed

src/Caching/SqlServer/src/Columns.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static class Indexes
2222
public const int ExpiresAtTimeIndex = 1;
2323
public const int SlidingExpirationInSecondsIndex = 2;
2424
public const int AbsoluteExpirationIndex = 3;
25-
public const int CacheItemValueIndex = 4;
25+
public const int CacheItemValueIndex = 0;
2626
}
2727
}
2828
}

src/Caching/SqlServer/src/DatabaseOperations.cs

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,6 @@ protected virtual byte[] GetCacheItem(string key, bool includeValue)
209209
}
210210

211211
byte[] value = null;
212-
TimeSpan? slidingExpiration = null;
213-
DateTimeOffset? absoluteExpiration = null;
214-
DateTimeOffset expirationTime;
215212
using (var connection = new SqlConnection(ConnectionString))
216213
using (var command = new SqlCommand(query, connection))
217214
{
@@ -226,22 +223,6 @@ protected virtual byte[] GetCacheItem(string key, bool includeValue)
226223
{
227224
if (reader.Read())
228225
{
229-
var id = reader.GetFieldValue<string>(Columns.Indexes.CacheItemIdIndex);
230-
231-
expirationTime = reader.GetFieldValue<DateTimeOffset>(Columns.Indexes.ExpiresAtTimeIndex);
232-
233-
if (!reader.IsDBNull(Columns.Indexes.SlidingExpirationInSecondsIndex))
234-
{
235-
slidingExpiration = TimeSpan.FromSeconds(
236-
reader.GetFieldValue<long>(Columns.Indexes.SlidingExpirationInSecondsIndex));
237-
}
238-
239-
if (!reader.IsDBNull(Columns.Indexes.AbsoluteExpirationIndex))
240-
{
241-
absoluteExpiration = reader.GetFieldValue<DateTimeOffset>(
242-
Columns.Indexes.AbsoluteExpirationIndex);
243-
}
244-
245226
if (includeValue)
246227
{
247228
value = reader.GetFieldValue<byte[]>(Columns.Indexes.CacheItemValueIndex);
@@ -274,9 +255,6 @@ protected virtual byte[] GetCacheItem(string key, bool includeValue)
274255
}
275256

276257
byte[] value = null;
277-
TimeSpan? slidingExpiration = null;
278-
DateTimeOffset? absoluteExpiration = null;
279-
DateTimeOffset expirationTime;
280258
using (var connection = new SqlConnection(ConnectionString))
281259
using (var command = new SqlCommand(query, connection))
282260
{
@@ -292,24 +270,6 @@ protected virtual byte[] GetCacheItem(string key, bool includeValue)
292270
{
293271
if (await reader.ReadAsync(token))
294272
{
295-
var id = await reader.GetFieldValueAsync<string>(Columns.Indexes.CacheItemIdIndex, token);
296-
297-
expirationTime = await reader.GetFieldValueAsync<DateTimeOffset>(
298-
Columns.Indexes.ExpiresAtTimeIndex, token);
299-
300-
if (!await reader.IsDBNullAsync(Columns.Indexes.SlidingExpirationInSecondsIndex, token))
301-
{
302-
slidingExpiration = TimeSpan.FromSeconds(
303-
await reader.GetFieldValueAsync<long>(Columns.Indexes.SlidingExpirationInSecondsIndex, token));
304-
}
305-
306-
if (!await reader.IsDBNullAsync(Columns.Indexes.AbsoluteExpirationIndex, token))
307-
{
308-
absoluteExpiration = await reader.GetFieldValueAsync<DateTimeOffset>(
309-
Columns.Indexes.AbsoluteExpirationIndex,
310-
token);
311-
}
312-
313273
if (includeValue)
314274
{
315275
value = await reader.GetFieldValueAsync<byte[]>(Columns.Indexes.CacheItemValueIndex, token);

src/Caching/SqlServer/src/MonoDatabaseOperations.cs

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ protected override byte[] GetCacheItem(string key, bool includeValue)
3434
}
3535

3636
byte[] value = null;
37-
TimeSpan? slidingExpiration = null;
38-
DateTimeOffset? absoluteExpiration = null;
39-
DateTimeOffset expirationTime;
4037
using (var connection = new SqlConnection(ConnectionString))
4138
{
4239
var command = new SqlCommand(query, connection);
@@ -50,22 +47,6 @@ protected override byte[] GetCacheItem(string key, bool includeValue)
5047

5148
if (reader.Read())
5249
{
53-
var id = reader.GetString(Columns.Indexes.CacheItemIdIndex);
54-
55-
expirationTime = DateTimeOffset.Parse(reader[Columns.Indexes.ExpiresAtTimeIndex].ToString());
56-
57-
if (!reader.IsDBNull(Columns.Indexes.SlidingExpirationInSecondsIndex))
58-
{
59-
slidingExpiration = TimeSpan.FromSeconds(
60-
reader.GetInt64(Columns.Indexes.SlidingExpirationInSecondsIndex));
61-
}
62-
63-
if (!reader.IsDBNull(Columns.Indexes.AbsoluteExpirationIndex))
64-
{
65-
absoluteExpiration = DateTimeOffset.Parse(
66-
reader[Columns.Indexes.AbsoluteExpirationIndex].ToString());
67-
}
68-
6950
if (includeValue)
7051
{
7152
value = (byte[])reader[Columns.Indexes.CacheItemValueIndex];
@@ -97,9 +78,6 @@ protected override byte[] GetCacheItem(string key, bool includeValue)
9778
}
9879

9980
byte[] value = null;
100-
TimeSpan? slidingExpiration = null;
101-
DateTimeOffset? absoluteExpiration = null;
102-
DateTimeOffset expirationTime;
10381
using (var connection = new SqlConnection(ConnectionString))
10482
{
10583
var command = new SqlCommand(SqlQueries.GetCacheItem, connection);
@@ -115,22 +93,6 @@ protected override byte[] GetCacheItem(string key, bool includeValue)
11593

11694
if (await reader.ReadAsync(token))
11795
{
118-
var id = reader.GetString(Columns.Indexes.CacheItemIdIndex);
119-
120-
expirationTime = DateTimeOffset.Parse(reader[Columns.Indexes.ExpiresAtTimeIndex].ToString());
121-
122-
if (!await reader.IsDBNullAsync(Columns.Indexes.SlidingExpirationInSecondsIndex, token))
123-
{
124-
slidingExpiration = TimeSpan.FromSeconds(
125-
Convert.ToInt64(reader[Columns.Indexes.SlidingExpirationInSecondsIndex].ToString()));
126-
}
127-
128-
if (!await reader.IsDBNullAsync(Columns.Indexes.AbsoluteExpirationIndex, token))
129-
{
130-
absoluteExpiration = DateTimeOffset.Parse(
131-
reader[Columns.Indexes.AbsoluteExpirationIndex].ToString());
132-
}
133-
13496
if (includeValue)
13597
{
13698
value = (byte[])reader[Columns.Indexes.CacheItemValueIndex];

src/Caching/SqlServer/src/SqlQueries.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ internal class SqlQueries
2828
"AND (AbsoluteExpiration IS NULL OR AbsoluteExpiration <> ExpiresAtTime) ;";
2929

3030
private const string GetCacheItemFormat =
31-
"SELECT Id, ExpiresAtTime, SlidingExpirationInSeconds, AbsoluteExpiration, Value " +
31+
"SELECT Value " +
3232
"FROM {0} WHERE Id = @Id AND @UtcNow <= ExpiresAtTime;";
3333

3434
private const string SetCacheItemFormat =

0 commit comments

Comments
 (0)