Ejemplo n.º 1
0
 /// <summary>查找统计行</summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public static AppMinuteStat FindOrAdd(TraceStatModel model)
 {
     // 高并发下获取或新增对象
     return(GetOrAdd(model, FindByTrace, m => new AppMinuteStat {
         StatTime = m.Time, AppId = m.AppId
     }));
 }
Ejemplo n.º 2
0
 /// <summary>查找统计行</summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public static TraceHourStat FindOrAdd(TraceStatModel model)
 {
     // 高并发下获取或新增对象
     return(GetOrAdd(model, FindByTrace, m => new TraceHourStat {
         StatTime = m.Time, AppId = m.AppId, Name = m.Name
     }));
 }
Ejemplo n.º 3
0
        // Select Count(ID) as ID,Category From AppMinuteStat Where CreateTime>'2020-01-24 00:00:00' Group By Category Order By ID Desc limit 20
        //static readonly FieldCache<AppMinuteStat> _CategoryCache = new FieldCache<AppMinuteStat>(nameof(Category))
        //{
        //Where = _.CreateTime > DateTime.Today.AddDays(-30) & Expression.Empty
        //};

        ///// <summary>获取类别列表,字段缓存10分钟,分组统计数据最多的前20种,用于魔方前台下拉选择</summary>
        ///// <returns></returns>
        //public static IDictionary<String, String> GetCategoryList() => _CategoryCache.FindAllName();
        #endregion

        #region 业务操作
        private static AppMinuteStat FindByTrace(TraceStatModel model, Boolean cache)
        {
            var key = $"AppMinuteStat:FindByTrace:{model.Key}";

            if (cache && _cache.TryGetValue <AppMinuteStat>(key, out var st))
            {
                return(st);
            }

            using var span = DefaultTracer.Instance?.NewSpan("AppMinuteStat-FindByTrace", model.Key);

            st = FindAllByAppIdWithCache(model.AppId, model.Time.Date)
                 .FirstOrDefault(e => e.StatTime == model.Time);

            // 查询数据库
            if (st == null)
            {
                st = Find(_.StatTime == model.Time & _.AppId == model.AppId);
            }

            if (st != null)
            {
                _cache.Set(key, st, 60);
            }

            return(st);
        }
Ejemplo n.º 4
0
        private static TraceHourStat FindByTrace(TraceStatModel model, Boolean cache)
        {
            var key = $"TraceHourStat:FindByTrace:{model.Key}";

            if (cache && _cache.TryGetValue <TraceHourStat>(key, out var st))
            {
                return(st);
            }

            st = FindAllByAppIdWithCache(model.AppId, model.Time.Date)
                 .FirstOrDefault(e => e.StatTime == model.Time && e.Name.EqualIgnoreCase(model.Name));

            // 查询数据库
            if (st == null)
            {
                st = Find(_.StatTime == model.Time & _.AppId == model.AppId & _.Name == model.Name);
            }

            if (st != null)
            {
                _cache.Set(key, st, 60);
            }

            return(st);
        }