optimize code and fix bug
This commit is contained in:
parent
9285698ee4
commit
c60146d614
|
@ -28,7 +28,6 @@ func configs(h *wp.Handle) {
|
|||
h.PushCacheGroupHeadScript(constraints.AllScene, "colorSchemeCss", 10.0056, colorSchemeCss)
|
||||
h.CommonComponents()
|
||||
components.WidgetArea(h)
|
||||
wp.ReplyCommentJs(h)
|
||||
h.SetData("customHeader", customHeader(h))
|
||||
wp.PushIndexHandler(constraints.PipeRender, h, wp.NewHandleFn(wp.IndexRender, 50.005, "wp.IndexRender"))
|
||||
h.PushRender(constraints.Detail, wp.NewHandleFn(wp.DetailRender, 50.005, "wp.DetailRender"))
|
||||
|
|
|
@ -69,7 +69,6 @@ func configs(h *wp.Handle) {
|
|||
h.SetData("colophon", colophon)
|
||||
setPaginationAndRender(h)
|
||||
h.CommonComponents()
|
||||
wp.ReplyCommentJs(h)
|
||||
h.PushPostPlugin(postThumbnail)
|
||||
wp.SetComponentsArgsForMap(widgets.Search, "{$form}", searchForm)
|
||||
wp.PushIndexHandler(constraints.PipeRender, h, wp.NewHandleFn(wp.IndexRender, 10.005, "wp.IndexRender"))
|
||||
|
|
|
@ -39,24 +39,21 @@ func (h *Handle) HookComponents(scene string, fn func(Components[string]) (Compo
|
|||
handleComponentHook.Store(scene, v)
|
||||
}
|
||||
|
||||
var getComponentFn = reload.BuildMapFn[string]("scene-components", getComponent)
|
||||
var hookComponentFn = reload.BuildMapFn[string]("calComponents", hookComponent)
|
||||
var GetComponents = reload.BuildMapFn[string]("scene-components", getComponent)
|
||||
var HookComponents = reload.BuildMapFnWithAnyParams[string]("calComponents", hookComponent)
|
||||
|
||||
type componentParam struct {
|
||||
components []Components[string]
|
||||
k string
|
||||
}
|
||||
|
||||
func hookComponent(p componentParam) []Components[string] {
|
||||
func hookComponent(a ...any) []Components[string] {
|
||||
k := a[0].(string)
|
||||
components := a[1].([]Components[string])
|
||||
mut := reload.GetGlobeMutex()
|
||||
mut.Lock()
|
||||
allHooks := slice.FilterAndToMap(p.components, func(t Components[string], _ int) (string, []func(Components[string]) (Components[string], bool), bool) {
|
||||
fn, ok := handleComponentHook.Load(p.k)
|
||||
return p.k, fn, ok
|
||||
allHooks := slice.FilterAndToMap(components, func(t Components[string], _ int) (string, []func(Components[string]) (Components[string], bool), bool) {
|
||||
fn, ok := handleComponentHook.Load(k)
|
||||
return k, fn, ok
|
||||
})
|
||||
mut.Unlock()
|
||||
r := slice.FilterAndMap(p.components, func(component Components[string]) (Components[string], bool) {
|
||||
hooks, ok := allHooks[p.k]
|
||||
r := slice.FilterAndMap(components, func(component Components[string]) (Components[string], bool) {
|
||||
hooks, ok := allHooks[k]
|
||||
if !ok {
|
||||
return component, true
|
||||
}
|
||||
|
@ -100,10 +97,10 @@ func cacheComponentFn(a cacheComponentParm[string]) string {
|
|||
}
|
||||
|
||||
func CalComponents(h *Handle) {
|
||||
allComponents := getComponentFn(str.Join("allScene-", h.scene), h)
|
||||
allComponents := GetComponents(str.Join("allScene-", h.scene), h)
|
||||
for k, components := range allComponents {
|
||||
key := str.Join("calComponents-", h.scene, "-", k)
|
||||
hookedComponents := hookComponentFn(key, componentParam{components, k})
|
||||
hookedComponents := HookComponents(key, k, components)
|
||||
var s = make([]string, 0, len(hookedComponents))
|
||||
for _, component := range hookedComponents {
|
||||
if component.Val != "" {
|
||||
|
|
|
@ -248,6 +248,7 @@ func (h *Handle) CommonComponents() {
|
|||
h.PushCacheGroupHeadScript(constraints.AllScene, "siteIconAndCustomCss", 0, CalSiteIcon, CalCustomCss)
|
||||
h.PushRender(constraints.AllStats, NewHandleFn(CalComponents, 10.001, "wp.CalComponents"))
|
||||
h.PushRender(constraints.AllStats, NewHandleFn(PreRenderTemplate, 0, "wp.PreRenderTemplate"))
|
||||
ReplyCommentJs(h)
|
||||
AdditionScript(h)
|
||||
}
|
||||
|
||||
|
|
2
cache/reload/reload.go
vendored
2
cache/reload/reload.go
vendored
|
@ -132,7 +132,7 @@ func BuildMapFnWithAnyParams[K comparable, V any](namespace string, fn func(...a
|
|||
if ok {
|
||||
return v
|
||||
}
|
||||
v = fn(a)
|
||||
v = fn(a...)
|
||||
m.Val.Store(key, v)
|
||||
return v
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user