Skip to content

Commit

Permalink
use ILIKE for searching
Browse files Browse the repository at this point in the history
  • Loading branch information
zensh committed May 28, 2020
1 parent 4cf203f commit a70e7b7
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 54 deletions.
44 changes: 22 additions & 22 deletions src/model/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (ms *Models) ApplyLabelRulesAndRefreshUserLabels(ctx context.Context, userI
}
}

if elapsed := time.Now().UTC().Sub(now) / time.Millisecond; elapsed > 100 {
if elapsed := time.Now().UTC().Sub(now) / time.Millisecond; elapsed > 200 {
logging.Warningf("ApplyLabelRulesAndRefreshUserLabels: userID %d, consumed %d ms, refreshed %v, start %v\n",
userID, elapsed, ok, now)
}
Expand All @@ -83,7 +83,7 @@ func (ms *Models) ApplyLabelRulesAndRefreshUserLabels(ctx context.Context, userI
func (ms *Models) TryApplyLabelRulesAndRefreshUserLabels(ctx context.Context, userID int64, now time.Time, force bool) *schema.User {
user, err := ms.ApplyLabelRulesAndRefreshUserLabels(ctx, userID, now, force)
if err != nil {
logging.Errf("ApplyLabelRulesAndRefreshUserLabels: userID %d, error %v", userID, err)
logging.Warningf("ApplyLabelRulesAndRefreshUserLabels: userID %d, error %v", userID, err)
return nil
}
return user
Expand All @@ -99,7 +99,7 @@ func (ms *Models) TryApplySettingRules(ctx context.Context, productID, userID in
// 此处不要释放锁,锁期不再执行对应 setting rule
// defer ms.Model.unlock(ctx, key)
if err := ms.SettingRule.ApplyRules(ctx, productID, userID); err != nil {
logging.Errf("%s error: %v", key, err)
logging.Warningf("%s error: %v", key, err)
}
}

Expand Down Expand Up @@ -310,15 +310,15 @@ func (m *Model) unlock(ctx context.Context, key string) {
sd := m.DB.Delete(schema.TableLock).Where(goqu.C("name").Eq(key))
_, err := service.DeResult(sd.Executor().ExecContext(ctx))
if err != nil {
logging.Errf("unlock: key %s, error %v", key, err)
logging.Warningf("unlock: key %s, error %v", key, err)
}
}

// tryRefreshLabelStatus 更新指定 label 的 Status(环境标签灰度进度,被作用的用户数,非精确)值
// 比如用户因为属于 n 个群组而被重复设置环境标签
func (m *Model) tryRefreshLabelStatus(ctx context.Context, labelID int64) {
if err := m.refreshLabelStatus(ctx, labelID); err != nil {
logging.Errf("tryRefreshLabelStatus: labelID %d, error %v", labelID, err)
logging.Infof("tryRefreshLabelStatus: labelID %d, error %v", labelID, err)
}
}
func (m *Model) refreshLabelStatus(ctx context.Context, labelID int64) error {
Expand Down Expand Up @@ -355,7 +355,7 @@ func (m *Model) refreshLabelStatus(ctx context.Context, labelID int64) error {
// 比如用户因为属于 n 个群组而被重复设置配置项
func (m *Model) tryRefreshSettingStatus(ctx context.Context, settingID int64) {
if err := m.refreshSettingStatus(ctx, settingID); err != nil {
logging.Errf("tryRefreshSettingStatus: settingID %d, error %v", settingID, err)
logging.Infof("tryRefreshSettingStatus: settingID %d, error %v", settingID, err)
}
}
func (m *Model) refreshSettingStatus(ctx context.Context, settingID int64) error {
Expand Down Expand Up @@ -391,7 +391,7 @@ func (m *Model) refreshSettingStatus(ctx context.Context, settingID int64) error
// tryRefreshGroupStatus 更新指定 group 的 Status(成员数量统计)值
func (m *Model) tryRefreshGroupStatus(ctx context.Context, groupID int64) {
if err := m.refreshGroupStatus(ctx, groupID); err != nil {
logging.Errf("tryRefreshGroupStatus: groupID %d, error %v", groupID, err)
logging.Infof("tryRefreshGroupStatus: groupID %d, error %v", groupID, err)
}
}
func (m *Model) refreshGroupStatus(ctx context.Context, groupID int64) error {
Expand All @@ -414,7 +414,7 @@ func (m *Model) refreshGroupStatus(ctx context.Context, groupID int64) error {
// tryRefreshModuleStatus 更新指定 module 的 Status(功能模块的配置项统计)值
func (m *Model) tryRefreshModuleStatus(ctx context.Context, moduleID int64) {
if err := m.refreshModuleStatus(ctx, moduleID); err != nil {
logging.Errf("tryRefreshModuleStatus: moduleID %d, error %v", moduleID, err)
logging.Infof("tryRefreshModuleStatus: moduleID %d, error %v", moduleID, err)
}
}
func (m *Model) refreshModuleStatus(ctx context.Context, moduleID int64) error {
Expand All @@ -437,7 +437,7 @@ func (m *Model) refreshModuleStatus(ctx context.Context, moduleID int64) error {
// tryIncreaseStatisticStatus 加减指定 key 的统计值
func (m *Model) tryIncreaseStatisticStatus(ctx context.Context, key schema.StatisticKey, delta int) {
if err := m.increaseStatisticStatus(ctx, key, delta); err != nil {
logging.Errf("tryIncreaseStatisticStatus: key %s, delta: %d, error %v", key, delta, err)
logging.Infof("tryIncreaseStatisticStatus: key %s, delta: %d, error %v", key, delta, err)
}
}
func (m *Model) increaseStatisticStatus(ctx context.Context, key schema.StatisticKey, delta int) error {
Expand Down Expand Up @@ -478,7 +478,7 @@ func (m *Model) updateStatisticValue(ctx context.Context, key schema.StatisticKe
// tryRefreshUsersTotalSize 更新用户总数
func (m *Model) tryRefreshUsersTotalSize(ctx context.Context) {
if err := m.refreshUsersTotalSize(ctx); err != nil {
logging.Errf("refreshUsersTotalSize: error %v", err)
logging.Infof("refreshUsersTotalSize: error %v", err)
}
}
func (m *Model) refreshUsersTotalSize(ctx context.Context) error {
Expand All @@ -499,7 +499,7 @@ func (m *Model) refreshUsersTotalSize(ctx context.Context) error {
// tryRefreshGroupsTotalSize 更新群组总数
func (m *Model) tryRefreshGroupsTotalSize(ctx context.Context) {
if err := m.refreshGroupsTotalSize(ctx); err != nil {
logging.Errf("refreshGroupsTotalSize: error %v", err)
logging.Infof("refreshGroupsTotalSize: error %v", err)
}
}
func (m *Model) refreshGroupsTotalSize(ctx context.Context) error {
Expand All @@ -520,7 +520,7 @@ func (m *Model) refreshGroupsTotalSize(ctx context.Context) error {
// tryRefreshProductsTotalSize 更新产品总数
func (m *Model) tryRefreshProductsTotalSize(ctx context.Context) {
if err := m.refreshProductsTotalSize(ctx); err != nil {
logging.Errf("refreshProductsTotalSize: error %v", err)
logging.Infof("refreshProductsTotalSize: error %v", err)
}
}
func (m *Model) refreshProductsTotalSize(ctx context.Context) error {
Expand All @@ -541,7 +541,7 @@ func (m *Model) refreshProductsTotalSize(ctx context.Context) error {
// tryRefreshLabelsTotalSize 更新标签总数
func (m *Model) tryRefreshLabelsTotalSize(ctx context.Context) {
if err := m.refreshLabelsTotalSize(ctx); err != nil {
logging.Errf("refreshLabelsTotalSize: error %v", err)
logging.Infof("refreshLabelsTotalSize: error %v", err)
}
}
func (m *Model) refreshLabelsTotalSize(ctx context.Context) error {
Expand All @@ -562,7 +562,7 @@ func (m *Model) refreshLabelsTotalSize(ctx context.Context) error {
// tryRefreshModulesTotalSize 更新模块总数
func (m *Model) tryRefreshModulesTotalSize(ctx context.Context) {
if err := m.refreshModulesTotalSize(ctx); err != nil {
logging.Errf("refreshModulesTotalSize: error %v", err)
logging.Infof("refreshModulesTotalSize: error %v", err)
}
}
func (m *Model) refreshModulesTotalSize(ctx context.Context) error {
Expand All @@ -583,7 +583,7 @@ func (m *Model) refreshModulesTotalSize(ctx context.Context) error {
// tryRefreshSettingsTotalSize 更新配置项总数
func (m *Model) tryRefreshSettingsTotalSize(ctx context.Context) {
if err := m.refreshSettingsTotalSize(ctx); err != nil {
logging.Errf("refreshSettingsTotalSize: error %v", err)
logging.Infof("refreshSettingsTotalSize: error %v", err)
}
}
func (m *Model) refreshSettingsTotalSize(ctx context.Context) error {
Expand All @@ -603,7 +603,7 @@ func (m *Model) refreshSettingsTotalSize(ctx context.Context) error {

func (m *Model) tryIncreaseLabelsStatus(ctx context.Context, labelIDs []int64, delta int) {
if err := m.increaseLabelsStatus(ctx, labelIDs, delta); err != nil {
logging.Errf("increaseLabelsStatus: labelIDs [%v], delta: %d, error %v", labelIDs, delta, err)
logging.Infof("increaseLabelsStatus: labelIDs [%v], delta: %d, error %v", labelIDs, delta, err)
}
}
func (m *Model) increaseLabelsStatus(ctx context.Context, labelIDs []int64, delta int) error {
Expand All @@ -623,7 +623,7 @@ func (m *Model) increaseLabelsStatus(ctx context.Context, labelIDs []int64, delt

func (m *Model) tryIncreaseSettingsStatus(ctx context.Context, settingIDs []int64, delta int) {
if err := m.increaseSettingsStatus(ctx, settingIDs, delta); err != nil {
logging.Errf("increaseSettingsStatus: settingIDs [%v], delta: %d, error %v", settingIDs, delta, err)
logging.Infof("increaseSettingsStatus: settingIDs [%v], delta: %d, error %v", settingIDs, delta, err)
}
}
func (m *Model) increaseSettingsStatus(ctx context.Context, settingIDs []int64, delta int) error {
Expand All @@ -643,7 +643,7 @@ func (m *Model) increaseSettingsStatus(ctx context.Context, settingIDs []int64,

func (m *Model) tryIncreaseModulesStatus(ctx context.Context, moduleIDs []int64, delta int) {
if err := m.increaseModulesStatus(ctx, moduleIDs, delta); err != nil {
logging.Errf("increaseModulesStatus: moduleIDs [%v], delta: %d, error %v", moduleIDs, delta, err)
logging.Infof("increaseModulesStatus: moduleIDs [%v], delta: %d, error %v", moduleIDs, delta, err)
}
}
func (m *Model) increaseModulesStatus(ctx context.Context, moduleIDs []int64, delta int) error {
Expand All @@ -670,7 +670,7 @@ func (m *Model) tryDeleteUserAndGroupLabels(ctx context.Context, labelIDs []int6
}
}
if err != nil {
logging.Errf("deleteUserAndGroupLabels with label_id [%v] error: %v", labelIDs, err)
logging.Warningf("deleteUserAndGroupLabels with label_id [%v] error: %v", labelIDs, err)
}
}

Expand All @@ -680,7 +680,7 @@ func (m *Model) tryDeleteLabelsRules(ctx context.Context, labelIDs []int64) {
_, err = m.deleteByCols(ctx, schema.TableLabelRule, goqu.Ex{"label_id": labelIDs})
}
if err != nil {
logging.Errf("deleteLabelsRules with label_id [%v] error: %v", labelIDs, err)
logging.Warningf("deleteLabelsRules with label_id [%v] error: %v", labelIDs, err)
}
}

Expand All @@ -693,7 +693,7 @@ func (m *Model) tryDeleteUserAndGroupSettings(ctx context.Context, settingIDs []
}
}
if err != nil {
logging.Errf("deleteUserAndGroupSettings with setting_id [%v] error: %v", settingIDs, err)
logging.Warningf("deleteUserAndGroupSettings with setting_id [%v] error: %v", settingIDs, err)
}
}

Expand All @@ -703,6 +703,6 @@ func (m *Model) tryDeleteSettingsRules(ctx context.Context, settingIDs []int64)
_, err = m.deleteByCols(ctx, schema.TableSettingRule, goqu.Ex{"setting_id": settingIDs})
}
if err != nil {
logging.Errf("deleteSettingsRules with setting_id [%v] error: %v", settingIDs, err)
logging.Warningf("deleteSettingsRules with setting_id [%v] error: %v", settingIDs, err)
}
}
16 changes: 8 additions & 8 deletions src/model/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ func (m *Group) Find(ctx context.Context, kind string, pg tpl.Pagination) ([]sch
sd = sd.Where(goqu.C("kind").Eq(kind))
}
if pg.Q != "" {
sdc = sdc.Where(goqu.C("uid").Like(pg.Q))
sd = sd.Where(goqu.C("uid").Like(pg.Q))
sdc = sdc.Where(goqu.C("uid").ILike(pg.Q))
sd = sd.Where(goqu.C("uid").ILike(pg.Q))
}
sd = sd.Order(goqu.C("id").Desc()).Limit(uint(pg.PageSize + 1))

Expand Down Expand Up @@ -112,8 +112,8 @@ func (m *Group) FindLabels(ctx context.Context, groupID int64, pg tpl.Pagination
goqu.I("t1.label_id").Eq(goqu.I("t2.id")))

if pg.Q != "" {
sdc = sdc.Where(goqu.I("t2.name").Like(pg.Q))
sd = sd.Where(goqu.I("t2.name").Like(pg.Q))
sdc = sdc.Where(goqu.I("t2.name").ILike(pg.Q))
sd = sd.Where(goqu.I("t2.name").ILike(pg.Q))
}

sdc = sdc.Where(goqu.I("t2.product_id").Eq(goqu.I("t3.id")))
Expand Down Expand Up @@ -197,8 +197,8 @@ func (m *Group) FindSettings(ctx context.Context, groupID, productID, moduleID,
}

if pg.Q != "" {
sdc = sdc.Where(goqu.I("t2.name").Like(pg.Q))
sd = sd.Where(goqu.I("t2.name").Like(pg.Q))
sdc = sdc.Where(goqu.I("t2.name").ILike(pg.Q))
sd = sd.Where(goqu.I("t2.name").ILike(pg.Q))
}

sdc = sdc.Where(goqu.I("t2.module_id").Eq(goqu.I("t3.id")))
Expand Down Expand Up @@ -341,8 +341,8 @@ func (m *Group) FindMembers(ctx context.Context, groupID int64, pg tpl.Paginatio
goqu.I("t1.user_id").Eq(goqu.I("t2.id")))

if pg.Q != "" {
sdc = sdc.Where(goqu.I("t2.uid").Like(pg.Q))
sd = sd.Where(goqu.I("t2.uid").Like(pg.Q))
sdc = sdc.Where(goqu.I("t2.uid").ILike(pg.Q))
sd = sd.Where(goqu.I("t2.uid").ILike(pg.Q))
}

sd = sd.Order(goqu.I("t1.id").Desc()).Limit(uint(pg.PageSize + 1))
Expand Down
12 changes: 6 additions & 6 deletions src/model/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ func (m *Label) Find(ctx context.Context, productID int64, pg tpl.Pagination) ([
goqu.C("offline_at").IsNull())

if pg.Q != "" {
sdc = sdc.Where(goqu.C("name").Like(pg.Q))
sd = sd.Where(goqu.C("name").Like(pg.Q))
sdc = sdc.Where(goqu.C("name").ILike(pg.Q))
sd = sd.Where(goqu.C("name").ILike(pg.Q))
}

sd = sd.Order(goqu.C("id").Desc()).Limit(uint(pg.PageSize + 1))
Expand Down Expand Up @@ -308,8 +308,8 @@ func (m *Label) ListUsers(ctx context.Context, labelID int64, pg tpl.Pagination)
goqu.I("t1.user_id").Eq(goqu.I("t2.id")))

if pg.Q != "" {
sdc = sdc.Where(goqu.I("t2.uid").Like(pg.Q))
sd = sd.Where(goqu.I("t2.uid").Like(pg.Q))
sdc = sdc.Where(goqu.I("t2.uid").ILike(pg.Q))
sd = sd.Where(goqu.I("t2.uid").ILike(pg.Q))
}

sd = sd.Order(goqu.I("t1.id").Desc()).Limit(uint(pg.PageSize + 1))
Expand Down Expand Up @@ -369,8 +369,8 @@ func (m *Label) ListGroups(ctx context.Context, labelID int64, pg tpl.Pagination
goqu.I("t1.group_id").Eq(goqu.I("t2.id")))

if pg.Q != "" {
sdc = sdc.Where(goqu.I("t2.uid").Like(pg.Q))
sd = sd.Where(goqu.I("t2.uid").Like(pg.Q))
sdc = sdc.Where(goqu.I("t2.uid").ILike(pg.Q))
sd = sd.Where(goqu.I("t2.uid").ILike(pg.Q))
}

sd = sd.Order(goqu.I("t1.id").Desc()).Limit(uint(pg.PageSize + 1))
Expand Down
4 changes: 2 additions & 2 deletions src/model/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ func (m *Module) Find(ctx context.Context, productID int64, pg tpl.Pagination) (
goqu.C("offline_at").IsNull())

if pg.Q != "" {
sdc = sdc.Where(goqu.C("name").Like(pg.Q))
sd = sd.Where(goqu.C("name").Like(pg.Q))
sdc = sdc.Where(goqu.C("name").ILike(pg.Q))
sd = sd.Where(goqu.C("name").ILike(pg.Q))
}

sd = sd.Order(goqu.C("id").Desc()).Limit(uint(pg.PageSize + 1))
Expand Down
4 changes: 2 additions & 2 deletions src/model/product.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ func (m *Product) Find(ctx context.Context, pg tpl.Pagination) ([]schema.Product
goqu.C("offline_at").IsNull())

if pg.Q != "" {
sdc = sdc.Where(goqu.C("name").Like(pg.Q))
sd = sd.Where(goqu.C("name").Like(pg.Q))
sdc = sdc.Where(goqu.C("name").ILike(pg.Q))
sd = sd.Where(goqu.C("name").ILike(pg.Q))
}

sd = sd.Order(goqu.C("id").Desc()).Limit(uint(pg.PageSize + 1))
Expand Down
12 changes: 6 additions & 6 deletions src/model/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ func (m *Setting) Find(ctx context.Context, productID, moduleID int64, pg tpl.Pa
goqu.I("t1.offline_at").IsNull())

if pg.Q != "" {
sdc = sdc.Where(goqu.I("t1.name").Like(pg.Q))
sd = sd.Where(goqu.I("t1.name").Like(pg.Q))
sdc = sdc.Where(goqu.I("t1.name").ILike(pg.Q))
sd = sd.Where(goqu.I("t1.name").ILike(pg.Q))
}

sd = sd.Order(goqu.I("t1.id").Desc()).Limit(uint(pg.PageSize + 1))
Expand Down Expand Up @@ -379,8 +379,8 @@ func (m *Setting) ListUsers(ctx context.Context, settingID int64, pg tpl.Paginat
goqu.I("t1.user_id").Eq(goqu.I("t2.id")))

if pg.Q != "" {
sdc = sdc.Where(goqu.I("t2.uid").Like(pg.Q))
sd = sd.Where(goqu.I("t2.uid").Like(pg.Q))
sdc = sdc.Where(goqu.I("t2.uid").ILike(pg.Q))
sd = sd.Where(goqu.I("t2.uid").ILike(pg.Q))
}

sd = sd.Order(goqu.I("t1.id").Desc()).Limit(uint(pg.PageSize + 1))
Expand Down Expand Up @@ -442,8 +442,8 @@ func (m *Setting) ListGroups(ctx context.Context, settingID int64, pg tpl.Pagina
goqu.I("t1.group_id").Eq(goqu.I("t2.id")))

if pg.Q != "" {
sdc = sdc.Where(goqu.I("t2.uid").Like(pg.Q))
sd = sd.Where(goqu.I("t2.uid").Like(pg.Q))
sdc = sdc.Where(goqu.I("t2.uid").ILike(pg.Q))
sd = sd.Where(goqu.I("t2.uid").ILike(pg.Q))
}

sd = sd.Order(goqu.I("t1.id").Desc()).Limit(uint(pg.PageSize + 1))
Expand Down
16 changes: 8 additions & 8 deletions src/model/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ func (m *User) Find(ctx context.Context, pg tpl.Pagination) ([]schema.User, int,
var total int64
var err error
if pg.Q != "" {
sdc = sdc.Where(goqu.C("uid").Like(pg.Q))
sdc = sdc.Where(goqu.C("uid").ILike(pg.Q))
total, err = sdc.CountContext(ctx)
if err != nil {
return nil, 0, err
}

sd = sd.Where(goqu.C("uid").Like(pg.Q))
sd = sd.Where(goqu.C("uid").ILike(pg.Q))
}

sd = sd.Order(goqu.C("id").Desc()).Limit(uint(pg.PageSize + 1))
Expand Down Expand Up @@ -237,7 +237,7 @@ func (m *User) FindSettingsUnionAll(ctx context.Context, groupIDs []int64, userI
}

if pg.Q != "" {
sd = sd.Where(goqu.I("t2.name").Like(pg.Q))
sd = sd.Where(goqu.I("t2.name").ILike(pg.Q))
}

sd = sd.Where(
Expand Down Expand Up @@ -267,7 +267,7 @@ func (m *User) FindSettingsUnionAll(ctx context.Context, groupIDs []int64, userI
}

if pg.Q != "" {
gsd = gsd.Where(goqu.I("t2.name").Like(pg.Q))
gsd = gsd.Where(goqu.I("t2.name").ILike(pg.Q))
}

gsd = gsd.Where(
Expand Down Expand Up @@ -362,8 +362,8 @@ func (m *User) FindLabels(ctx context.Context, userID int64, pg tpl.Pagination)
goqu.I("t1.label_id").Eq(goqu.I("t2.id")))

if pg.Q != "" {
sdc = sdc.Where(goqu.I("t2.name").Like(pg.Q))
sd = sd.Where(goqu.I("t2.name").Like(pg.Q))
sdc = sdc.Where(goqu.I("t2.name").ILike(pg.Q))
sd = sd.Where(goqu.I("t2.name").ILike(pg.Q))
}

sdc = sdc.Where(goqu.I("t2.product_id").Eq(goqu.I("t3.id")))
Expand Down Expand Up @@ -446,8 +446,8 @@ func (m *User) FindSettings(ctx context.Context, userID, productID, moduleID, se
}

if pg.Q != "" {
sdc = sdc.Where(goqu.I("t2.name").Like(pg.Q))
sd = sd.Where(goqu.I("t2.name").Like(pg.Q))
sdc = sdc.Where(goqu.I("t2.name").ILike(pg.Q))
sd = sd.Where(goqu.I("t2.name").ILike(pg.Q))
}

sdc = sdc.Where(goqu.I("t2.module_id").Eq(goqu.I("t3.id")))
Expand Down

0 comments on commit a70e7b7

Please sign in to comment.