From aacb485deb144ff64bdb11cdab537a652f5176b0 Mon Sep 17 00:00:00 2001 From: harveyshao Date: Fri, 25 Nov 2022 14:38:46 +0800 Subject: [PATCH] opt mdb --- base/mdb/hash.go | 3 +++ base/mdb/list.go | 3 ++- base/mdb/zone.go | 31 +++++++++++++++++++++---------- core/chat/demo.go | 9 +++++---- core/code/favor.go | 2 +- 5 files changed, 32 insertions(+), 16 deletions(-) diff --git a/base/mdb/hash.go b/base/mdb/hash.go index 9f4c845e..35098bfb 100644 --- a/base/mdb/hash.go +++ b/base/mdb/hash.go @@ -34,6 +34,9 @@ func _hash_insert(m *ice.Message, prefix, chain string, arg ...string) string { if expire := m.Conf(prefix, kit.Keys(chain, kit.Keym(EXPIRE))); expire != "" { arg = kit.Simple(TIME, m.Time(expire), arg) } + m.Debug("what %v %v", m.Conf(prefix, chain)) + m.Debug("what %v %v", kit.Data()) + m.Debug("what %v %v", m.Conf(prefix, chain)) return m.Echo(Rich(m, prefix, chain, kit.Data(arg, TARGET, m.Optionv(TARGET)))).Result() } func _hash_delete(m *ice.Message, prefix, chain, field, value string) { diff --git a/base/mdb/list.go b/base/mdb/list.go index b7ac57f5..23a3ef66 100644 --- a/base/mdb/list.go +++ b/base/mdb/list.go @@ -23,6 +23,7 @@ func _list_inputs(m *ice.Message, prefix, chain string, field, value string) { m.SortIntR(COUNT) }() defer RLock(m, prefix, chain)() + m.Debug("what %v %v", prefix, chain) Grows(m, prefix, chain, "", "", func(value ice.Map) { value = kit.GetMeta(value) list[kit.Format(value[field])] += kit.Int(kit.Select("1", value[COUNT])) @@ -120,8 +121,8 @@ func ListAction(arg ...ice.Any) ice.Actions { func PageListAction(arg ...ice.Any) ice.Actions { return ice.MergeActions(ice.Actions{ SELECT: {Name: "select id auto insert page", Hand: func(m *ice.Message, arg ...string) { ListSelect(m, arg...) }}, - PREV: {Hand: func(m *ice.Message, arg ...string) { PrevPage(m, m.Config(COUNT), kit.Slice(arg, 1)...) }}, NEXT: {Hand: func(m *ice.Message, arg ...string) { NextPageLimit(m, m.Config(COUNT), kit.Slice(arg, 1)...) }}, + PREV: {Hand: func(m *ice.Message, arg ...string) { PrevPage(m, m.Config(COUNT), kit.Slice(arg, 1)...) }}, }, ListAction(arg...)) } func ListField(m *ice.Message) string { return kit.Select(LIST_FIELD, m.Config(FIELD)) } diff --git a/base/mdb/zone.go b/base/mdb/zone.go index ed268822..b1201ef6 100644 --- a/base/mdb/zone.go +++ b/base/mdb/zone.go @@ -19,7 +19,7 @@ func _zone_inputs(m *ice.Message, prefix, chain, zone string, field, value strin return } h := _hash_select_field(m, prefix, chain, zone, HASH) - defer RLock(m, prefix, chain)() + defer Lock(m, prefix, chain)() _list_inputs(m, prefix, kit.Keys(chain, HASH, h), field, value) } func _zone_insert(m *ice.Message, prefix, chain, zone string, arg ...string) { @@ -115,7 +115,9 @@ func _zone_import(m *ice.Message, prefix, chain, file string) { case ID: continue case EXTRA: - kit.Value(data, k, kit.UnMarshal(line[i])) + if line[i] != "" { + kit.Value(data, k, kit.UnMarshal(line[i])) + } default: kit.Value(data, k, line[i]) } @@ -130,17 +132,17 @@ func _zone_import(m *ice.Message, prefix, chain, file string) { }() count++ } - m.Logs(IMPORT, KEY, path.Join(prefix, chain), FILE, p, COUNT, count) + m.Logs(IMPORT, KEY, path.Join(prefix, chain), FILE, kit.Keys(file, CSV), COUNT, count) m.Echo("%d", count) } const ( - ZONE_FIELD = "zone,id,time,type,name,text" + ZONE_FIELD = "time,id,type,name,text" ) const ZONE = "zone" -func ZoneAction(args ...ice.Any) ice.Actions { - return ice.Actions{ice.CTX_INIT: AutoConfig(append([]ice.Any{SHORT, ZONE}, args)...), +func ZoneAction(arg ...ice.Any) ice.Actions { + return ice.Actions{ice.CTX_INIT: AutoConfig(append(kit.List(SHORT, ZONE, FIELD, ZONE_FIELD), arg...)...), INPUTS: {Hand: func(m *ice.Message, arg ...string) { ZoneInputs(m, arg) }}, CREATE: {Hand: func(m *ice.Message, arg ...string) { ZoneCreate(m, arg) }}, REMOVE: {Hand: func(m *ice.Message, arg ...string) { ZoneRemove(m, arg) }}, @@ -149,10 +151,15 @@ func ZoneAction(args ...ice.Any) ice.Actions { SELECT: {Name: "select zone id auto insert", Hand: func(m *ice.Message, arg ...string) { ZoneSelect(m, arg...) }}, EXPORT: {Hand: func(m *ice.Message, arg ...string) { ZoneExport(m, arg) }}, IMPORT: {Hand: func(m *ice.Message, arg ...string) { ZoneImport(m, arg) }}, - PREV: {Hand: func(m *ice.Message, arg ...string) { PrevPage(m, arg[0], arg[1:]...) }}, - NEXT: {Hand: func(m *ice.Message, arg ...string) { NextPageLimit(m, arg[0], arg[1:]...) }}, } } +func PageZoneAction(arg ...ice.Any) ice.Actions { + return ice.MergeActions(ice.Actions{ + SELECT: {Name: "select zone id auto insert page", Hand: func(m *ice.Message, arg ...string) { PageZoneSelect(m, arg...) }}, + NEXT: {Hand: func(m *ice.Message, arg ...string) { NextPageLimit(m, arg[0], arg[1:]...) }}, + PREV: {Hand: func(m *ice.Message, arg ...string) { PrevPage(m, arg[0], arg[1:]...) }}, + }, ZoneAction(arg...)) +} func ZoneShort(m *ice.Message) string { return kit.Select(ZONE, m.Config(SHORT), m.Config(SHORT) != UNIQ) } @@ -172,7 +179,11 @@ func ZoneRemove(m *ice.Message, arg ...Any) { m.Cmdy(DELETE, m.PrefixKey(), "", HASH, arg) } func ZoneInsert(m *ice.Message, arg ...Any) { - m.Cmdy(INSERT, m.PrefixKey(), "", ZONE, arg) + if args := kit.Simple(arg...); args[0] == ZoneShort(m) { + m.Cmdy(INSERT, m.PrefixKey(), "", ZONE, args[1:]) + } else { + m.Cmdy(INSERT, m.PrefixKey(), "", ZONE, arg) + } } func ZoneModify(m *ice.Message, arg ...Any) { m.Cmdy(MODIFY, m.PrefixKey(), "", ZONE, m.Option(ZoneShort(m)), m.Option(ID), arg) @@ -200,7 +211,7 @@ func ZoneExport(m *ice.Message, arg ...Any) { func ZoneImport(m *ice.Message, arg ...Any) { m.Cmdy(IMPORT, m.PrefixKey(), "", ZONE, arg) } -func ZoneSelectPage(m *ice.Message, arg ...string) *ice.Message { +func PageZoneSelect(m *ice.Message, arg ...string) *ice.Message { OptionPages(m, kit.Slice(arg, 2)...) return ZoneSelect(m, arg...) } diff --git a/core/chat/demo.go b/core/chat/demo.go index 3ea73d83..691c0c16 100644 --- a/core/chat/demo.go +++ b/core/chat/demo.go @@ -8,10 +8,11 @@ import ( func init() { Index.MergeCommands(ice.Commands{ - "demo-hash": {Actions: ice.MergeActions(mdb.HashAction(), ctx.CmdAction())}, + "demo-hash": {Actions: ice.MergeActions(mdb.HashAction(), ctx.CmdAction())}, "demo-status-hash": {Actions: ice.MergeActions(mdb.StatusHashAction(), ctx.CmdAction())}, - "demo-list": {Actions: ice.MergeActions(mdb.ListAction(), ctx.CmdAction())}, - "demo-page-list": {Actions: ice.MergeActions(mdb.PageListAction(), ctx.CmdAction())}, - "demo-zone": {Actions: ice.MergeActions(mdb.ZoneAction(), ctx.CmdAction())}, + "demo-list": {Actions: ice.MergeActions(mdb.ListAction(), ctx.CmdAction())}, + "demo-page-list": {Actions: ice.MergeActions(mdb.PageListAction(), ctx.CmdAction())}, + "demo-zone": {Actions: ice.MergeActions(mdb.ZoneAction(), ctx.CmdAction())}, + "demo-page-zone": {Actions: ice.MergeActions(mdb.PageZoneAction(), ctx.CmdAction())}, }) } diff --git a/core/code/favor.go b/core/code/favor.go index 11a05318..d9066915 100644 --- a/core/code/favor.go +++ b/core/code/favor.go @@ -26,7 +26,7 @@ func init() { }}, }, mdb.ZoneAction(mdb.SHORT, mdb.ZONE, mdb.FIELD, "time,id,type,name,text,path,file,line")), Hand: func(m *ice.Message, arg ...string) { m.Option(mdb.CACHE_LIMIT, "30") - if mdb.ZoneSelectPage(m, arg...); len(arg) > 0 && arg[0] != "" { + if mdb.PageZoneSelect(m, arg...); len(arg) > 0 && arg[0] != "" { if arg[0] == "_recent_file" { m.Sort(nfs.FILE) }