forked from free-lancers/electricity_bill_calc_service
refactor(cache):缓存系统降级,停用全部数据缓存。
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"electricity_bill_calc/cache"
|
||||
"electricity_bill_calc/global"
|
||||
"electricity_bill_calc/logger"
|
||||
"electricity_bill_calc/repository"
|
||||
@@ -68,8 +67,6 @@ func (cs _ChargeService) RecordUserCharge(uid string, fee, discount, amount *flo
|
||||
cs.log.Error("提交数据库事务失败。", zap.Error(err))
|
||||
return false, err
|
||||
}
|
||||
cache.AbolishRelation("charge")
|
||||
cache.AbolishRelation(fmt.Sprintf("user:%s", uid))
|
||||
return true, nil
|
||||
}
|
||||
|
||||
@@ -114,7 +111,5 @@ func (cs _ChargeService) CancelUserCharge(uid string, seq int64) (bool, error) {
|
||||
cs.log.Error("提交数据库事务失败。", zap.Error(err))
|
||||
return false, err
|
||||
}
|
||||
cache.AbolishRelation("charge")
|
||||
cache.AbolishRelation(fmt.Sprintf("user:%s", uid))
|
||||
return true, nil
|
||||
}
|
||||
|
@@ -1,13 +1,11 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"electricity_bill_calc/cache"
|
||||
"electricity_bill_calc/excel"
|
||||
"electricity_bill_calc/global"
|
||||
"electricity_bill_calc/logger"
|
||||
"electricity_bill_calc/model"
|
||||
"electricity_bill_calc/repository"
|
||||
"electricity_bill_calc/tools"
|
||||
"electricity_bill_calc/types"
|
||||
"electricity_bill_calc/vo"
|
||||
"fmt"
|
||||
@@ -69,8 +67,6 @@ func (ms _MeterService) CreateMeterRecord(pid string, form *vo.MeterCreationForm
|
||||
tx.Rollback(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
cache.AbolishRelation(fmt.Sprintf("meter:%s", pid))
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -104,8 +100,6 @@ func (ms _MeterService) UpdateMeterRecord(pid string, code string, form *vo.Mete
|
||||
tx.Rollback(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
cache.AbolishRelation(fmt.Sprintf("meter:%s", pid))
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -446,7 +440,6 @@ func (ms _MeterService) ReplaceMeter(
|
||||
tx.Rollback(ctx)
|
||||
return err
|
||||
}
|
||||
cache.AbolishRelation(fmt.Sprintf("meter:%s", pid))
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -474,16 +467,6 @@ func (ms _MeterService) ListPooledMeterRelations(pid, masterMeter string) ([]*mo
|
||||
// 列出指定园区中所有的公摊表计
|
||||
func (ms _MeterService) SearchPooledMetersDetail(pid string, page uint, keyword *string) ([]*model.PooledMeterDetailCompound, int64, error) {
|
||||
ms.log.Info("列出指定园区中所有的公摊表计", zap.String("park id", pid), zap.Uint("page", page), zap.String("keyword", *keyword))
|
||||
cacheConditions := []string{
|
||||
pid,
|
||||
fmt.Sprintf("%d", page),
|
||||
tools.DefaultTo(keyword, "UNDEFINED"),
|
||||
}
|
||||
if meters, total, err := cache.RetrievePagedSearch[[]*model.PooledMeterDetailCompound]("assemble_pooled_meters_detail", cacheConditions...); err == nil {
|
||||
ms.log.Info("已经从缓存中获取到了指定园区中所有的公摊表计。", zap.Int("count", len(*meters)), zap.Int64("total", total))
|
||||
return *meters, total, nil
|
||||
}
|
||||
|
||||
poolingMeters, total, err := repository.MeterRepository.ListPoolingMeters(pid, page, keyword)
|
||||
if err != nil {
|
||||
ms.log.Error("无法列出指定园区中所有的公摊表计。", zap.Error(err))
|
||||
@@ -530,8 +513,6 @@ func (ms _MeterService) SearchPooledMetersDetail(pid string, page uint, keyword
|
||||
})
|
||||
}
|
||||
|
||||
cache.CachePagedSearch(assembled, total, []string{fmt.Sprintf("meter:%s", pid), fmt.Sprintf("meter_relation:%s", pid)}, "assemble_pooled_meter_detail", cacheConditions...)
|
||||
|
||||
return assembled, total, nil
|
||||
}
|
||||
|
||||
@@ -567,7 +548,6 @@ func (ms _MeterService) BindMeter(pid, masterMeter string, slaveMeters []string)
|
||||
tx.Rollback(ctx)
|
||||
return false, err
|
||||
}
|
||||
cache.AbolishRelation(fmt.Sprintf("meter:%s", pid))
|
||||
return true, nil
|
||||
}
|
||||
|
||||
@@ -603,7 +583,6 @@ func (ms _MeterService) UnbindMeter(pid, masterMeter string, slaveMeters []strin
|
||||
tx.Rollback(ctx)
|
||||
return false, err
|
||||
}
|
||||
cache.AbolishRelation(fmt.Sprintf("meter:%s", pid))
|
||||
return true, nil
|
||||
}
|
||||
|
||||
|
@@ -1,7 +1,6 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"electricity_bill_calc/cache"
|
||||
"electricity_bill_calc/global"
|
||||
"electricity_bill_calc/logger"
|
||||
"electricity_bill_calc/model"
|
||||
@@ -62,7 +61,6 @@ func (ts _TenementService) CreateTenementRecord(pid string, creationForm *vo.Ten
|
||||
tx.Rollback(ctx)
|
||||
return fmt.Errorf("未能提交数据库事务,%w", err)
|
||||
}
|
||||
cache.AbolishRelation(fmt.Sprintf("tenement:%s", pid))
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -108,8 +106,6 @@ func (ts _TenementService) BindMeter(pid, tid, meterCode string, reading *vo.Met
|
||||
tx.Rollback(ctx)
|
||||
return fmt.Errorf("未能提交数据库事务,%w", err)
|
||||
}
|
||||
cache.AbolishRelation(fmt.Sprintf("tenement:%s", pid))
|
||||
cache.AbolishRelation(fmt.Sprintf("meter:%s", pid))
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -155,8 +151,6 @@ func (ts _TenementService) UnbindMeter(pid, tid, meterCode string, reading *vo.M
|
||||
tx.Rollback(ctx)
|
||||
return fmt.Errorf("未能提交数据库事务,%w", err)
|
||||
}
|
||||
cache.AbolishRelation(fmt.Sprintf("tenement:%s", pid))
|
||||
cache.AbolishRelation(fmt.Sprintf("meter:%s", pid))
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -243,8 +237,5 @@ func (ts _TenementService) MoveOutTenement(pid, tid string, reading []*vo.MeterR
|
||||
tx.Rollback(ctx)
|
||||
return fmt.Errorf("未能提交数据库事务,%w", err)
|
||||
}
|
||||
|
||||
cache.AbolishRelation(fmt.Sprintf("tenement:%s", pid))
|
||||
cache.AbolishRelation(fmt.Sprintf("meter:%s", pid))
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user