Skip to content

优化ReduxStore与广播机制 - #729

Merged
CodFrm merged 10 commits into
scriptscat:mainfrom
cyfung1031:no-redux-scriptlist-1
Sep 16, 2025
Merged

CodFrm merged 10 commits into
scriptscat:mainfrom
cyfung1031:no-redux-scriptlist-1

Conversation

@cyfung1031

@cyfung1031 cyfung1031 commented Sep 13, 2025 •

Copy link
Copy Markdown
Collaborator

现在ScriptList是用Redux Store
但根本不需要。因为打开那一刻取一下,之后用事件机制就能进行更新
使用Redux Store的话,即使关掉页面也不会释放资讯
这是没必要的Cache

另外,事件机制的设计,未考虑批次删除,批次启用,批次禁用等处理
现在都改成批次事件
减少大量事件讯息传来传去

而且也改善了 事件讯息的资讯量。把不用的资讯量除去。

另外,修了删除跟新增时,其他script列表页面没更新sort的问题

改善后的机制:
在三个Tab打开了同一Script列表页
其中一个把部份Script删除 -> 发指示【执行批次删除】到 ServiceWorker -> ServiceWorker 处理 -> 广播【批次删除发生】
三个Tab同时收到广播【批次删除发生】,然后更新页面


其他代码优化

1) window.location.search.split("=")[1]; -> new URLSearchParams(location.search).get("uuid");
2) upsertScript -> mUpsertScript ( 避免變數名和function名一樣)
3) transform: "translateY(1px)", -> flex 排版

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR optimizes the Redux Store and broadcast mechanism for script management. It removes Redux Store usage from script lists in favor of event-based updates to prevent unnecessary caching and improves batch operations handling.

  • Replaces Redux Store with direct state management and event subscription for better memory management
  • Implements batch operations for delete, enable, and sort operations to reduce message traffic
  • Optimizes event message data size by removing unnecessary information

Reviewed Changes

Copilot reviewed 24 out of 24 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/pages/store/utils.ts Converts loadScriptFavicons to async generator for batch processing
src/pages/store/subscribe.ts Removes Redux Store subscription handlers
src/pages/store/store.ts Removes script slice from Redux Store
src/pages/store/features/script.ts Converts Redux actions to plain async functions
src/pages/options/routes/ScriptList.tsx Replaces Redux Store with local state and event subscriptions
src/pages/options/main.tsx Removes store subscription initialization
src/pages/install/App.tsx Fixes variable naming conflict and URL parameter parsing
src/pages/confirm/App.tsx Improves URL parameter parsing with URLSearchParams
src/pages/popup/App.tsx Removes CSS transform, adds flex layout for menu items
src/app/service/service_worker/script.ts Implements batch operations for scripts (delete, enable, sort)
src/app/service/queue.ts Updates message types for batch operations

Comment thread src/pages/options/routes/ScriptList.tsx
Comment thread src/app/repo/repo.ts
Comment thread src/app/service/service_worker/script.ts
@CodFrm

CodFrm commented Sep 14, 2025 •

Copy link
Copy Markdown
Member

使用Redux Store也是一次尝试,至少我觉得他将数据、操作和组件抽离开来这块是有意义的

现在这样的话,我觉得可以考虑封装一个 useScriptlist 的 hook,不然全塞一个组件里面,似乎不是很合适,而且看起来很乱,就比如,每个地方都要写上:updateScriptListMultiple,如此的话,把Redux Store删掉我也是赞成的

https://github.com/scriptscat/scriptcat/pull/729/files#diff-07a95531e28c44aa894b838993b28f9cee480d32e1a3c7e9f3ade5cf00ba44dfR916-R918

Comment thread packages/message/message_queue.ts
Comment thread src/app/service/service_worker/script.ts Outdated
Comment thread src/app/service/service_worker/script.ts Outdated
@cyfung1031

Copy link
Copy Markdown
Collaborator Author

使用Redux Store也是一次尝试,至少我觉得他将数据、操作和组件抽离开来这块是有意义的

现在这样的话,我觉得可以考虑封装一个 useScriptlist 的 hook,不然全塞一个组件里面,似乎不是很合适,而且看起来很乱,就比如,每个地方都要写上:updateScriptListMultiple,如此的话,把Redux Store删掉我也是赞成的

https://github.com/scriptscat/scriptcat/pull/729/files#diff-07a95531e28c44aa894b838993b28f9cee480d32e1a3c7e9f3ade5cf00ba44dfR916-R918

React的Redux用在单一页面跑SPA是很有用
但ScriptCat是一个插件
把显示页关掉后,React的东西都是清不掉
所以不需要缓存的部份不要使用Redux

@cyfung1031

Copy link
Copy Markdown
Collaborator Author

9596f07
想了一下還是不爭論了
就按你說的改就好了

@cyfung1031

cyfung1031 commented Sep 15, 2025 •

Copy link
Copy Markdown
Collaborator Author

使用Redux Store也是一次尝试,至少我觉得他将数据、操作和组件抽离开来这块是有意义的

现在这样的话,我觉得可以考虑封装一个 useScriptlist 的 hook,不然全塞一个组件里面,似乎不是很合适,而且看起来很乱,就比如,每个地方都要写上:updateScriptListMultiple,如此的话,把Redux Store删掉我也是赞成的

https://github.com/scriptscat/scriptcat/pull/729/files#diff-07a95531e28c44aa894b838993b28f9cee480d32e1a3c7e9f3ade5cf00ba44dfR916-R918

updateScriptListMultiple 那个是为了你的 enableLoading 和 actionLoading
把那些 updateScriptListMultiple 全删也可以
现在的 scriptlist 是 array 不是 Map, 所以每次执行都要找 uuid
updateScriptListMultiple 只是一个Helper function
可以改名做 updateEntry


                        updateEntry([item.uuid], { actionLoading: true });
                        await requestStopScript(item.uuid);
                        updateEntry([item.uuid], { actionLoading: false });

这样的写法很清楚。前跟後


先合併這個。再另外提交改善

@CodFrm
CodFrm merged commit b62781e into scriptscat:main Sep 16, 2025
2 of 3 checks passed
@cyfung1031
cyfung1031 deleted the no-redux-scriptlist-1 branch October 4, 2025 02:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants