From 15f74bcab555cc0dbacf19d7f4e1fc2c400f4730 Mon Sep 17 00:00:00 2001 From: Rustem Mussabekov Date: Fri, 17 May 2024 18:53:01 +0300 Subject: [PATCH] Improve performance --- .../edit/form/collection/suggested.js | 4 +++- src/co/bookmarks/edit/form/tags/suggested.js | 3 +-- src/data/reducers/config.js | 2 +- src/data/sagas/bookmarks/single.js | 2 +- src/data/selectors/bookmarks/single.js | 22 +++++++++++-------- 5 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/co/bookmarks/edit/form/collection/suggested.js b/src/co/bookmarks/edit/form/collection/suggested.js index 8acc68dd..3bc22b74 100644 --- a/src/co/bookmarks/edit/form/collection/suggested.js +++ b/src/co/bookmarks/edit/form/collection/suggested.js @@ -7,9 +7,11 @@ import { isPro } from '~data/selectors/user' import Button from '~co/common/button' +const self = { self: true } + function Suggestion({ id, onClick }) { const getCollectionPath = useMemo(()=>makeCollectionPath(), []) - const path = useSelector(state=>getCollectionPath(state, id, { self: true })) + const path = useSelector(state=>getCollectionPath(state, id, self)) const shortPath = useMemo(()=>path.map((p)=>p.title).slice(-2).join(' / '), [path]) const fullPath = useMemo(()=>path.map((p)=>p.title).join(' / '), [path]) const collection = useMemo(()=>path?.[path.length-1], [path]) diff --git a/src/co/bookmarks/edit/form/tags/suggested.js b/src/co/bookmarks/edit/form/tags/suggested.js index 3ab2b5ad..752bad2e 100644 --- a/src/co/bookmarks/edit/form/tags/suggested.js +++ b/src/co/bookmarks/edit/form/tags/suggested.js @@ -27,8 +27,7 @@ export default function BookmarkEditFormTagsSuggested({ item, onTagClick }) { const enabled = useSelector(state=>state.config.ai_suggestions) const pro = useSelector(state=>isPro(state)) const getSuggestedFields = useMemo(()=>makeSuggestedFields(), []) - const suggestions = useSelector(state=>getSuggestedFields(state, item)) - const tags = useMemo(()=>(suggestions.tags||[]).filter(tag=>!item.tags.includes(tag)), [suggestions.tags, item.tags]) + const { tags=[] } = useSelector(state=>getSuggestedFields(state, item)) //click const onSuggestionClick = useCallback(e=>{ diff --git a/src/data/reducers/config.js b/src/data/reducers/config.js index 35e8e7f8..a85ffdea 100755 --- a/src/data/reducers/config.js +++ b/src/data/reducers/config.js @@ -81,7 +81,7 @@ const initialState = Immutable({ acknowledge: [], - ai_suggestions: false + ai_suggestions: true }) //this keys can be kept untouched on reset diff --git a/src/data/sagas/bookmarks/single.js b/src/data/sagas/bookmarks/single.js index 1eb8a46f..694a3467 100755 --- a/src/data/sagas/bookmarks/single.js +++ b/src/data/sagas/bookmarks/single.js @@ -362,7 +362,7 @@ function* reorder({ _id, ignore, order, collectionId }) { function* suggestFields({ obj, ignore }) { if (ignore) return; - if (!obj?.link) return; + if (!obj?.link && !obj?._id) return; try{ const { item } = obj._id ? diff --git a/src/data/selectors/bookmarks/single.js b/src/data/selectors/bookmarks/single.js index 909cba5d..183b2809 100755 --- a/src/data/selectors/bookmarks/single.js +++ b/src/data/selectors/bookmarks/single.js @@ -53,14 +53,18 @@ export const makeCreatorRef = ()=>createSelector( export const makeSuggestedFields = ()=>createSelector( [ ({bookmarks}, { link })=>bookmarks.suggestedFields[link] || {}, - (_, { collectionId })=>collectionId + (_, { collectionId })=>collectionId, + (_, { tags })=>tags ], - ({ collections=[], tags=[] }, collectionId)=>({ - collections: collections?.[0] == collectionId ? - emptyArray : - [...collections] - .filter(cid=>cid!=collectionId) - .splice(0, 5), - tags - }) + ({ collections=[], tags=[] }, collectionId, itemTags)=>{ + return ({ + collections: collections?.[0] == collectionId ? + emptyArray : + [...collections] + .filter(cid=>cid!=collectionId) + .splice(0, 5), + tags: tags + .filter(tag=>!itemTags?.includes(tag)) + }) + } ) \ No newline at end of file