Compare commits

..

3 Commits

Author SHA1 Message Date
tiny-craft 77541ed371 perf: change the function buttons for database nodes to be persistent 2023-10-16 18:36:42 +08:00
tiny-craft e2a371ed14 perf: use pipeline for batch delete keys 2023-10-16 11:22:18 +08:00
tiny-craft 72144bc996 perf: add minimum window size
perf: maximize the window automatically if screen size is lower than minimum window size #19
2023-10-16 10:26:39 +08:00
7 changed files with 50 additions and 21 deletions

View File

@ -4,3 +4,5 @@ const DEFAULT_FONT_SIZE = 14
const DEFAULT_ASIDE_WIDTH = 300 const DEFAULT_ASIDE_WIDTH = 300
const DEFAULT_WINDOW_WIDTH = 1024 const DEFAULT_WINDOW_WIDTH = 1024
const DEFAULT_WINDOW_HEIGHT = 768 const DEFAULT_WINDOW_HEIGHT = 768
const MIN_WINDOW_WIDTH = 960
const MIN_WINDOW_HEIGHT = 640

View File

@ -1343,22 +1343,36 @@ func (c *connectionService) DeleteKey(connName string, db int, k any, async bool
// delete by prefix // delete by prefix
var mutex sync.Mutex var mutex sync.Mutex
del := func(ctx context.Context, cli redis.UniversalClient) error { del := func(ctx context.Context, cli redis.UniversalClient) error {
iter := cli.Scan(ctx, 0, key, 10000).Iterator() handleDel := func(ks []string) error {
var fn func(c context.Context, ks ...string) *redis.IntCmd pipe := cli.Pipeline()
if async { for _, k2 := range ks {
fn = cli.Unlink if async {
} else { cli.Unlink(ctx, k2)
fn = cli.Del } else {
} cli.Del(ctx, k2)
for iter.Next(ctx) { }
subKey := iter.Val()
if err = fn(ctx, subKey).Err(); err != nil {
return err
} else {
mutex.Lock()
deletedKeys = append(deletedKeys, subKey)
mutex.Unlock()
} }
pipe.Exec(ctx)
mutex.Lock()
deletedKeys = append(deletedKeys, ks...)
mutex.Unlock()
return nil
}
iter := cli.Scan(ctx, 0, key, 10000).Iterator()
resultKeys := make([]string, 0, 100)
for iter.Next(ctx) {
resultKeys = append(resultKeys, iter.Val())
if len(resultKeys) >= 3 {
handleDel(resultKeys)
resultKeys = resultKeys[:0:cap(resultKeys)]
}
}
if len(resultKeys) > 0 {
handleDel(resultKeys)
} }
return nil return nil
} }

View File

@ -113,7 +113,7 @@ func (p *preferencesService) GetAppVersion() (resp types.JSResp) {
} }
func (p *preferencesService) SaveWindowSize(width, height int) { func (p *preferencesService) SaveWindowSize(width, height int) {
if width >= consts.DEFAULT_WINDOW_WIDTH && height >= consts.DEFAULT_WINDOW_HEIGHT { if width >= consts.MIN_WINDOW_WIDTH && height >= consts.MIN_WINDOW_HEIGHT {
p.UpdatePreferences(map[string]any{ p.UpdatePreferences(map[string]any{
"behavior.windowWidth": width, "behavior.windowWidth": width,
"behavior.windowHeight": height, "behavior.windowHeight": height,

View File

@ -6,6 +6,7 @@ import (
"log" "log"
"sync" "sync"
"time" "time"
"tinyrdm/backend/consts"
"tinyrdm/backend/types" "tinyrdm/backend/types"
) )
@ -28,6 +29,18 @@ func System() *systemService {
func (s *systemService) Start(ctx context.Context) { func (s *systemService) Start(ctx context.Context) {
s.ctx = ctx s.ctx = ctx
// maximize the window if screen size is lower than the minimum window size
if screen, err := runtime.ScreenGetAll(ctx); err == nil && len(screen) > 0 {
for _, sc := range screen {
if sc.IsCurrent {
if sc.Size.Width < consts.MIN_WINDOW_WIDTH || sc.Size.Height < consts.MIN_WINDOW_HEIGHT {
runtime.WindowMaximise(ctx)
break
}
}
}
}
} }
// SelectFile open file dialog to select a file // SelectFile open file dialog to select a file

View File

@ -47,8 +47,8 @@ func (p *PreferencesStorage) GetPreferences() (ret types.Preferences) {
ret = p.getPreferences() ret = p.getPreferences()
ret.Behavior.AsideWidth = max(ret.Behavior.AsideWidth, consts.DEFAULT_ASIDE_WIDTH) ret.Behavior.AsideWidth = max(ret.Behavior.AsideWidth, consts.DEFAULT_ASIDE_WIDTH)
ret.Behavior.WindowWidth = max(ret.Behavior.WindowWidth, consts.DEFAULT_WINDOW_WIDTH) ret.Behavior.WindowWidth = max(ret.Behavior.WindowWidth, consts.MIN_WINDOW_WIDTH)
ret.Behavior.WindowHeight = max(ret.Behavior.WindowHeight, consts.DEFAULT_WINDOW_HEIGHT) ret.Behavior.WindowHeight = max(ret.Behavior.WindowHeight, consts.MIN_WINDOW_HEIGHT)
return return
} }

View File

@ -529,7 +529,7 @@ const getValueMenu = () => {
// render menu function icon // render menu function icon
const renderSuffix = ({ option }) => { const renderSuffix = ({ option }) => {
if (includes(selectedKeys.value, option.key)) { if ((option.type === ConnectionType.RedisDB && option.opened) || includes(selectedKeys.value, option.key)) {
switch (option.type) { switch (option.type) {
case ConnectionType.RedisDB: case ConnectionType.RedisDB:
return renderIconMenu(getDatabaseMenu(option.opened)) return renderIconMenu(getDatabaseMenu(option.opened))

View File

@ -44,8 +44,8 @@ func main() {
Title: "Tiny RDM", Title: "Tiny RDM",
Width: windowWidth, Width: windowWidth,
Height: windowHeight, Height: windowHeight,
MinWidth: consts.DEFAULT_WINDOW_WIDTH, MinWidth: consts.MIN_WINDOW_WIDTH,
MinHeight: consts.DEFAULT_WINDOW_HEIGHT, MinHeight: consts.MIN_WINDOW_HEIGHT,
Frameless: runtime.GOOS != "darwin", Frameless: runtime.GOOS != "darwin",
Menu: appMenu, Menu: appMenu,
AssetServer: &assetserver.Options{ AssetServer: &assetserver.Options{