diff options
Diffstat (limited to 'MediaBrowser.Server.Implementations/Security/AuthenticationRepository.cs')
| -rw-r--r-- | MediaBrowser.Server.Implementations/Security/AuthenticationRepository.cs | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/MediaBrowser.Server.Implementations/Security/AuthenticationRepository.cs b/MediaBrowser.Server.Implementations/Security/AuthenticationRepository.cs index 43a960ea2..cd20ad74d 100644 --- a/MediaBrowser.Server.Implementations/Security/AuthenticationRepository.cs +++ b/MediaBrowser.Server.Implementations/Security/AuthenticationRepository.cs @@ -157,12 +157,6 @@ namespace MediaBrowser.Server.Implementations.Security var startIndex = query.StartIndex ?? 0; - if (startIndex > 0) - { - whereClauses.Add(string.Format("Id NOT IN (SELECT Id FROM AccessTokens ORDER BY DateCreated LIMIT {0})", - startIndex.ToString(_usCulture))); - } - if (!string.IsNullOrWhiteSpace(query.AccessToken)) { whereClauses.Add("AccessToken=@AccessToken"); @@ -187,11 +181,27 @@ namespace MediaBrowser.Server.Implementations.Security cmd.Parameters.Add(cmd, "@IsActive", DbType.Boolean).Value = query.IsActive.Value; } - if (whereClauses.Count > 0) + var whereTextWithoutPaging = whereClauses.Count == 0 ? + string.Empty : + " where " + string.Join(" AND ", whereClauses.ToArray()); + + if (startIndex > 0) { - cmd.CommandText += " where " + string.Join(" AND ", whereClauses.ToArray()); + var pagingWhereText = whereClauses.Count == 0 ? + string.Empty : + " where " + string.Join(" AND ", whereClauses.ToArray()); + + whereClauses.Add(string.Format("Id NOT IN (SELECT Id FROM AccessTokens {0} ORDER BY DateCreated LIMIT {1})", + pagingWhereText, + startIndex.ToString(_usCulture))); } + var whereText = whereClauses.Count == 0 ? + string.Empty : + " where " + string.Join(" AND ", whereClauses.ToArray()); + + cmd.CommandText += whereText; + cmd.CommandText += " ORDER BY DateCreated"; if (query.Limit.HasValue) @@ -199,7 +209,7 @@ namespace MediaBrowser.Server.Implementations.Security cmd.CommandText += " LIMIT " + query.Limit.Value.ToString(_usCulture); } - cmd.CommandText += "; select count (Id) from AccessTokens"; + cmd.CommandText += "; select count (Id) from AccessTokens" + whereTextWithoutPaging; var list = new List<AuthenticationInfo>(); var count = 0; |
