From f24252d6ab3bc46ae2e246e5461ed378e7e395e6 Mon Sep 17 00:00:00 2001 From: alimy Date: Sat, 11 Jun 2022 08:19:30 +0800 Subject: [PATCH] optimize #78 change CacheIndex configure in conf.yaml to SimpleCacheIndex --- config.yaml.sample | 4 +-- internal/conf/conf.go | 54 ++++++++++++++++++------------------- internal/conf/settting.go | 2 +- internal/dao/cache_index.go | 2 +- internal/dao/dao.go | 6 ++--- 5 files changed, 34 insertions(+), 34 deletions(-) diff --git a/config.yaml.sample b/config.yaml.sample index 5aa7eb49..7579428b 100644 --- a/config.yaml.sample +++ b/config.yaml.sample @@ -16,7 +16,7 @@ Features: Develop: ["Base", "Option", "Sms", "AliOSS", "LoggerZinc"] Slim: ["Base", "LocalOSS", "LoggerFile"] Base: ["Zinc", "MySQL", "Redis", "Alipay",] - Option: ["CacheIndex"] + Option: ["SimpleCacheIndex"] Sms: "SmsJuhe" SmsJuhe: Key: @@ -25,7 +25,7 @@ SmsJuhe: Alipay: AppID: PrivateKey: -CacheIndex: # 缓存泡泡广场消息流 +SimpleCacheIndex: # 缓存泡泡广场消息流 MaxIndexSize: 200 # 最大缓存条数 CheckTickDuration: 60 # 循环自检查每多少秒一次 ExpireTickDuration: 300 # 每多少秒后强制过期缓存 diff --git a/internal/conf/conf.go b/internal/conf/conf.go index 4ba67b07..827bbce1 100644 --- a/internal/conf/conf.go +++ b/internal/conf/conf.go @@ -13,18 +13,18 @@ var ( redisSetting *RedisSettingS features *FeaturesSettingS - ServerSetting *ServerSettingS - AppSetting *AppSettingS - CacheIndexSetting *CacheIndexSettingS - SmsJuheSetting *SmsJuheSettings - AlipaySetting *AlipaySettingS - ZincSetting *ZincSettingS - AliOSSSetting *AliOSSSettingS - MinIOSetting *MinIOSettingS - S3Setting *S3SettingS - LocalOSSSetting *LocalOSSSettingS - JWTSetting *JWTSettingS - Mutex *sync.Mutex + ServerSetting *ServerSettingS + AppSetting *AppSettingS + SimpleCacheIndexSetting *SimpleCacheIndexSettingS + SmsJuheSetting *SmsJuheSettings + AlipaySetting *AlipaySettingS + ZincSetting *ZincSettingS + AliOSSSetting *AliOSSSettingS + MinIOSetting *MinIOSettingS + S3Setting *S3SettingS + LocalOSSSetting *LocalOSSSettingS + JWTSetting *JWTSettingS + Mutex *sync.Mutex ) func setupSetting(suite []string, noDefault bool) error { @@ -41,21 +41,21 @@ func setupSetting(suite []string, noDefault bool) error { } objects := map[string]interface{}{ - "App": &AppSetting, - "Server": &ServerSetting, - "CacheIndex": &CacheIndexSetting, - "Alipay": &AlipaySetting, - "SmsJuhe": &SmsJuheSetting, - "LoggerFile": &loggerFileSetting, - "LoggerZinc": &loggerZincSetting, - "MySQL": &mySQLSetting, - "Zinc": &ZincSetting, - "Redis": &redisSetting, - "JWT": &JWTSetting, - "AliOSS": &AliOSSSetting, - "MinIO": &MinIOSetting, - "LocalOSS": &LocalOSSSetting, - "S3": &S3Setting, + "App": &AppSetting, + "Server": &ServerSetting, + "SimpleCacheIndex": &SimpleCacheIndexSetting, + "Alipay": &AlipaySetting, + "SmsJuhe": &SmsJuheSetting, + "LoggerFile": &loggerFileSetting, + "LoggerZinc": &loggerZincSetting, + "MySQL": &mySQLSetting, + "Zinc": &ZincSetting, + "Redis": &redisSetting, + "JWT": &JWTSetting, + "AliOSS": &AliOSSSetting, + "MinIO": &MinIOSetting, + "LocalOSS": &LocalOSSSetting, + "S3": &S3Setting, } if err = setting.Unmarshal(objects); err != nil { return err diff --git a/internal/conf/settting.go b/internal/conf/settting.go index 3c572b30..aa37e923 100644 --- a/internal/conf/settting.go +++ b/internal/conf/settting.go @@ -46,7 +46,7 @@ type AppSettingS struct { TronApiKeys []string } -type CacheIndexSettingS struct { +type SimpleCacheIndexSettingS struct { MaxIndexSize int CheckTickDuration int ExpireTickDuration int diff --git a/internal/dao/cache_index.go b/internal/dao/cache_index.go index c457987d..c469b3e6 100644 --- a/internal/dao/cache_index.go +++ b/internal/dao/cache_index.go @@ -10,7 +10,7 @@ import ( ) func newSimpleCacheIndexServant(getIndexPosts func(offset, limit int) ([]*model.PostFormated, error)) *simpleCacheIndexServant { - s := conf.CacheIndexSetting + s := conf.SimpleCacheIndexSetting cacheIndex := &simpleCacheIndexServant{ getIndexPosts: getIndexPosts, maxIndexSize: s.MaxIndexSize, diff --git a/internal/dao/dao.go b/internal/dao/dao.go index df97701b..59634bfb 100644 --- a/internal/dao/dao.go +++ b/internal/dao/dao.go @@ -71,11 +71,11 @@ func NewDataService(engine *gorm.DB, zinc *zinc.ZincClient) core.DataService { } // initialize CacheIndex if needed - if !conf.CfgIf("CacheIndex") { - ds.useCacheIndex = false - } else { + if conf.CfgIf("SimpleCacheIndex") { ds.useCacheIndex = true ds.cacheIndex = newSimpleCacheIndexServant(ds.getIndexPosts) + } else { + ds.useCacheIndex = false } return ds