feat: Splits search api by resources to improve query time [cw-47] (#6942)
* feat: Splits search api by resources to improve query time * Review fixes * Spacing fixes * Update app/javascript/dashboard/modules/search/components/SearchView.vue Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com> * Review fixes * Refactor searchview --------- Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com> Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
This commit is contained in:
committed by
GitHub
parent
5600b518ac
commit
402428fb4d
@@ -2,9 +2,15 @@ import SearchAPI from '../../api/search';
|
||||
import types from '../mutation-types';
|
||||
export const initialState = {
|
||||
records: [],
|
||||
fullSearchRecords: {},
|
||||
contactRecords: [],
|
||||
conversationRecords: [],
|
||||
messageRecords: [],
|
||||
uiFlags: {
|
||||
isFetching: false,
|
||||
isSearchCompleted: false,
|
||||
contact: { isFetching: false },
|
||||
conversation: { isFetching: false },
|
||||
message: { isFetching: false },
|
||||
},
|
||||
};
|
||||
|
||||
@@ -12,8 +18,14 @@ export const getters = {
|
||||
getConversations(state) {
|
||||
return state.records;
|
||||
},
|
||||
getFullSearchRecords(state) {
|
||||
return state.fullSearchRecords;
|
||||
getContactRecords(state) {
|
||||
return state.contactRecords;
|
||||
},
|
||||
getConversationRecords(state) {
|
||||
return state.conversationRecords;
|
||||
},
|
||||
getMessageRecords(state) {
|
||||
return state.messageRecords;
|
||||
},
|
||||
getUIFlags(state) {
|
||||
return state.uiFlags;
|
||||
@@ -40,23 +52,67 @@ export const actions = {
|
||||
});
|
||||
}
|
||||
},
|
||||
async fullSearch({ commit }, { q }) {
|
||||
commit(types.FULL_SEARCH_SET, []);
|
||||
async fullSearch({ commit, dispatch }, { q }) {
|
||||
if (!q) {
|
||||
return;
|
||||
}
|
||||
commit(types.FULL_SEARCH_SET_UI_FLAG, { isFetching: true });
|
||||
commit(types.FULL_SEARCH_SET_UI_FLAG, {
|
||||
isFetching: true,
|
||||
isSearchCompleted: false,
|
||||
});
|
||||
try {
|
||||
const { data } = await SearchAPI.get({ q });
|
||||
commit(types.FULL_SEARCH_SET, data.payload);
|
||||
dispatch('contactSearch', { q });
|
||||
dispatch('conversationSearch', { q });
|
||||
dispatch('messageSearch', { q });
|
||||
} catch (error) {
|
||||
// Ignore error
|
||||
} finally {
|
||||
commit(types.FULL_SEARCH_SET_UI_FLAG, { isFetching: false });
|
||||
commit(types.FULL_SEARCH_SET_UI_FLAG, {
|
||||
isFetching: false,
|
||||
isSearchCompleted: true,
|
||||
});
|
||||
}
|
||||
},
|
||||
async contactSearch({ commit }, { q }) {
|
||||
commit(types.CONTACT_SEARCH_SET, []);
|
||||
commit(types.CONTACT_SEARCH_SET_UI_FLAG, { isFetching: true });
|
||||
try {
|
||||
const { data } = await SearchAPI.contacts({ q });
|
||||
commit(types.CONTACT_SEARCH_SET, data.payload.contacts);
|
||||
} catch (error) {
|
||||
// Ignore error
|
||||
} finally {
|
||||
commit(types.CONTACT_SEARCH_SET_UI_FLAG, { isFetching: false });
|
||||
}
|
||||
},
|
||||
async conversationSearch({ commit }, { q }) {
|
||||
commit(types.CONVERSATION_SEARCH_SET, []);
|
||||
commit(types.CONVERSATION_SEARCH_SET_UI_FLAG, { isFetching: true });
|
||||
try {
|
||||
const { data } = await SearchAPI.conversations({ q });
|
||||
commit(types.CONVERSATION_SEARCH_SET, data.payload.conversations);
|
||||
} catch (error) {
|
||||
// Ignore error
|
||||
} finally {
|
||||
commit(types.CONVERSATION_SEARCH_SET_UI_FLAG, { isFetching: false });
|
||||
}
|
||||
},
|
||||
async messageSearch({ commit }, { q }) {
|
||||
commit(types.MESSAGE_SEARCH_SET, []);
|
||||
commit(types.MESSAGE_SEARCH_SET_UI_FLAG, { isFetching: true });
|
||||
try {
|
||||
const { data } = await SearchAPI.messages({ q });
|
||||
commit(types.MESSAGE_SEARCH_SET, data.payload.messages);
|
||||
} catch (error) {
|
||||
// Ignore error
|
||||
} finally {
|
||||
commit(types.MESSAGE_SEARCH_SET_UI_FLAG, { isFetching: false });
|
||||
}
|
||||
},
|
||||
async clearSearchResults({ commit }) {
|
||||
commit(types.FULL_SEARCH_SET, {});
|
||||
commit(types.MESSAGE_SEARCH_SET, []);
|
||||
commit(types.CONVERSATION_SEARCH_SET, []);
|
||||
commit(types.CONTACT_SEARCH_SET, []);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -64,8 +120,14 @@ export const mutations = {
|
||||
[types.SEARCH_CONVERSATIONS_SET](state, records) {
|
||||
state.records = records;
|
||||
},
|
||||
[types.FULL_SEARCH_SET](state, records) {
|
||||
state.fullSearchRecords = records;
|
||||
[types.CONTACT_SEARCH_SET](state, records) {
|
||||
state.contactRecords = records;
|
||||
},
|
||||
[types.CONVERSATION_SEARCH_SET](state, records) {
|
||||
state.conversationRecords = records;
|
||||
},
|
||||
[types.MESSAGE_SEARCH_SET](state, records) {
|
||||
state.messageRecords = records;
|
||||
},
|
||||
[types.SEARCH_CONVERSATIONS_SET_UI_FLAG](state, uiFlags) {
|
||||
state.uiFlags = { ...state.uiFlags, ...uiFlags };
|
||||
@@ -73,6 +135,15 @@ export const mutations = {
|
||||
[types.FULL_SEARCH_SET_UI_FLAG](state, uiFlags) {
|
||||
state.uiFlags = { ...state.uiFlags, ...uiFlags };
|
||||
},
|
||||
[types.CONTACT_SEARCH_SET_UI_FLAG](state, uiFlags) {
|
||||
state.uiFlags.contact = { ...state.uiFlags.contact, ...uiFlags };
|
||||
},
|
||||
[types.CONVERSATION_SEARCH_SET_UI_FLAG](state, uiFlags) {
|
||||
state.uiFlags.conversation = { ...state.uiFlags.conversation, ...uiFlags };
|
||||
},
|
||||
[types.MESSAGE_SEARCH_SET_UI_FLAG](state, uiFlags) {
|
||||
state.uiFlags.message = { ...state.uiFlags.message, ...uiFlags };
|
||||
},
|
||||
};
|
||||
|
||||
export default {
|
||||
|
||||
@@ -269,6 +269,12 @@ export default {
|
||||
|
||||
// Full Search
|
||||
FULL_SEARCH_SET: 'FULL_SEARCH_SET',
|
||||
CONTACT_SEARCH_SET: 'CONTACT_SEARCH_SET',
|
||||
CONTACT_SEARCH_SET_UI_FLAG: 'CONTACT_SEARCH_SET_UI_FLAG',
|
||||
CONVERSATION_SEARCH_SET: 'CONVERSATION_SEARCH_SET',
|
||||
CONVERSATION_SEARCH_SET_UI_FLAG: 'CONVERSATION_SEARCH_SET_UI_FLAG',
|
||||
MESSAGE_SEARCH_SET: 'MESSAGE_SEARCH_SET',
|
||||
MESSAGE_SEARCH_SET_UI_FLAG: 'MESSAGE_SEARCH_SET_UI_FLAG',
|
||||
FULL_SEARCH_SET_UI_FLAG: 'FULL_SEARCH_SET_UI_FLAG',
|
||||
SET_CONVERSATION_PARTICIPANTS_UI_FLAG:
|
||||
'SET_CONVERSATION_PARTICIPANTS_UI_FLAG',
|
||||
|
||||
Reference in New Issue
Block a user