perf: 分页查询性能优化
This commit is contained in:
parent
db0fe72f07
commit
91c4ce98bd
|
@ -6,7 +6,7 @@ using System.Collections.Generic;
|
||||||
namespace Bootstrap.DataAccess
|
namespace Bootstrap.DataAccess
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// 操作日志实体类
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[TableName("Logs")]
|
[TableName("Logs")]
|
||||||
public class Log : Trace
|
public class Log : Trace
|
||||||
|
@ -31,7 +31,7 @@ namespace Bootstrap.DataAccess
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public virtual new Page<Log> RetrievePages(PaginationOption po, DateTime? startTime, DateTime? endTime, string opType)
|
public virtual new Page<Log> RetrievePages(PaginationOption po, DateTime? startTime, DateTime? endTime, string opType)
|
||||||
{
|
{
|
||||||
var sql = new Sql("select CRUD, UserName, LogTime, Ip, Browser, OS, City, RequestUrl, RequestData from Logs");
|
var sql = new Sql("select * from Logs");
|
||||||
if (startTime.HasValue) sql.Where("LogTime >= @0", startTime.Value);
|
if (startTime.HasValue) sql.Where("LogTime >= @0", startTime.Value);
|
||||||
if (endTime.HasValue) sql.Where("LogTime < @0", endTime.Value.AddDays(1).AddSeconds(-1));
|
if (endTime.HasValue) sql.Where("LogTime < @0", endTime.Value.AddDays(1).AddSeconds(-1));
|
||||||
if (startTime == null && endTime == null) sql.Where("LogTime > @0", DateTime.Today.AddMonths(0 - DictHelper.RetrieveExceptionsLogPeriod()));
|
if (startTime == null && endTime == null) sql.Where("LogTime > @0", DateTime.Today.AddMonths(0 - DictHelper.RetrieveExceptionsLogPeriod()));
|
||||||
|
@ -42,7 +42,7 @@ namespace Bootstrap.DataAccess
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// 查询所有操作日志
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="startTime"></param>
|
/// <param name="startTime"></param>
|
||||||
/// <param name="endTime"></param>
|
/// <param name="endTime"></param>
|
||||||
|
|
|
@ -6,58 +6,58 @@ using System.Collections.Generic;
|
||||||
namespace Bootstrap.DataAccess
|
namespace Bootstrap.DataAccess
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// 登录用户信息实体类
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[TableName("LoginLogs")]
|
[TableName("LoginLogs")]
|
||||||
public class LoginUser
|
public class LoginUser
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// 获得/设置 Id
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Id { get; set; }
|
public string Id { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// 获得/设置 用户名
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string UserName { get; set; }
|
public string UserName { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// 获得/设置 登录时间
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DateTime LoginTime { get; set; }
|
public DateTime LoginTime { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// 获得/设置 登录IP地址
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Ip { get; set; }
|
public string Ip { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// 获得/设置 登录浏览器
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Browser { get; set; }
|
public string Browser { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// 获得/设置 登录操作系统
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string OS { get; set; }
|
public string OS { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// 获得/设置 登录地点
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string City { get; set; }
|
public string City { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// 获得/设置 登录是否成功
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Result { get; set; }
|
public string Result { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// 获得/设置 用户 UserAgent
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string UserAgent { get; set; }
|
public string UserAgent { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// 保存登录用户数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="user"></param>
|
/// <param name="user"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
|
@ -69,7 +69,7 @@ namespace Bootstrap.DataAccess
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// 获得登录用户的分页数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="po"></param>
|
/// <param name="po"></param>
|
||||||
/// <param name="startTime"></param>
|
/// <param name="startTime"></param>
|
||||||
|
@ -78,7 +78,7 @@ namespace Bootstrap.DataAccess
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public virtual Page<LoginUser> RetrieveByPages(PaginationOption po, DateTime? startTime, DateTime? endTime, string ip)
|
public virtual Page<LoginUser> RetrieveByPages(PaginationOption po, DateTime? startTime, DateTime? endTime, string ip)
|
||||||
{
|
{
|
||||||
var sql = new Sql("select UserName, LoginTime, Ip, Browser, OS, City, Result from LoginLogs");
|
var sql = new Sql("select * from LoginLogs");
|
||||||
if (startTime.HasValue) sql.Where("LoginTime >= @0", startTime.Value);
|
if (startTime.HasValue) sql.Where("LoginTime >= @0", startTime.Value);
|
||||||
if (endTime.HasValue) sql.Where("LoginTime < @0", endTime.Value.AddDays(1));
|
if (endTime.HasValue) sql.Where("LoginTime < @0", endTime.Value.AddDays(1));
|
||||||
if (!string.IsNullOrEmpty(ip)) sql.Where("ip = @0", ip);
|
if (!string.IsNullOrEmpty(ip)) sql.Where("ip = @0", ip);
|
||||||
|
|
|
@ -6,7 +6,7 @@ using System.Collections.Generic;
|
||||||
namespace Bootstrap.DataAccess
|
namespace Bootstrap.DataAccess
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// 用户访问数据实体类
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[TableName("Traces")]
|
[TableName("Traces")]
|
||||||
public class Trace
|
public class Trace
|
||||||
|
@ -32,17 +32,17 @@ namespace Bootstrap.DataAccess
|
||||||
public string Ip { get; set; }
|
public string Ip { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// 获得/设置 客户端地点
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string City { get; set; }
|
public string City { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// 获得/设置 客户端浏览器
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Browser { get; set; }
|
public string Browser { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// 获得/设置 客户端操作系统
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string OS { get; set; }
|
public string OS { get; set; }
|
||||||
|
|
||||||
|
@ -52,12 +52,12 @@ namespace Bootstrap.DataAccess
|
||||||
public string RequestUrl { get; set; }
|
public string RequestUrl { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// 获得/设置 客户端 UserAgent
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string UserAgent { get; set; }
|
public string UserAgent { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 保存访问历史记录
|
/// 保存用户访问数据历史记录
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="p"></param>
|
/// <param name="p"></param>
|
||||||
public virtual bool Save(Trace p)
|
public virtual bool Save(Trace p)
|
||||||
|
@ -69,7 +69,7 @@ namespace Bootstrap.DataAccess
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// 查询用户访问分页数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="po"></param>
|
/// <param name="po"></param>
|
||||||
/// <param name="startTime"></param>
|
/// <param name="startTime"></param>
|
||||||
|
@ -78,7 +78,7 @@ namespace Bootstrap.DataAccess
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public virtual Page<Trace> RetrievePages(PaginationOption po, DateTime? startTime, DateTime? endTime, string ip)
|
public virtual Page<Trace> RetrievePages(PaginationOption po, DateTime? startTime, DateTime? endTime, string ip)
|
||||||
{
|
{
|
||||||
var sql = new Sql("select UserName, LogTime, IP, Browser, OS, City, RequestUrl from Traces");
|
var sql = new Sql("select * from Traces");
|
||||||
if (startTime.HasValue) sql.Where("LogTime > @0", startTime.Value);
|
if (startTime.HasValue) sql.Where("LogTime > @0", startTime.Value);
|
||||||
if (endTime.HasValue) sql.Where("LogTime < @0", endTime.Value.AddDays(1).AddSeconds(-1));
|
if (endTime.HasValue) sql.Where("LogTime < @0", endTime.Value.AddDays(1).AddSeconds(-1));
|
||||||
if (startTime == null && endTime == null) sql.Where("LogTime > @0", DateTime.Today.AddMonths(0 - DictHelper.RetrieveAccessLogPeriod()));
|
if (startTime == null && endTime == null) sql.Where("LogTime > @0", DateTime.Today.AddMonths(0 - DictHelper.RetrieveAccessLogPeriod()));
|
||||||
|
@ -89,7 +89,7 @@ namespace Bootstrap.DataAccess
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// 查询所有用户数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="startTime"></param>
|
/// <param name="startTime"></param>
|
||||||
/// <param name="endTime"></param>
|
/// <param name="endTime"></param>
|
||||||
|
|
Loading…
Reference in New Issue