TT#43501 Speed up convs requests by using no_count

Change-Id: If367877854734553a512632adc21c9358c10a05f
changes/58/23558/4
raxelsen 7 years ago committed by Hans-Peter Herzog
parent a8e7df6385
commit a14d686590

@ -43,10 +43,14 @@ export function getList(options) {
} }
}).then((res) => { }).then((res) => {
let body = getJsonBody(res.body); let body = getJsonBody(res.body);
let lastPage = Math.ceil( body.total_count / options.params.rows ); let totalCount = _.get(body, 'total_count', 0);
let lastPage = Math.ceil( totalCount / options.params.rows );
if(options.all === true) { if(options.all === true) {
lastPage = 1; lastPage = 1;
} }
if(lastPage === 0) {
lastPage = null;
}
resolve({ resolve({
items: _.get(body, options.root, []), items: _.get(body, options.root, []),
lastPage: lastPage lastPage: lastPage

@ -10,18 +10,20 @@ export function getConversations(options) {
let type = _.get(options, 'type', null); let type = _.get(options, 'type', null);
let params ={ let params ={
subscriber_id: _.get(options, 'subscriberId'), subscriber_id: _.get(options, 'subscriberId'),
page: _.get(options, 'page', 1),
rows: _.get(options, 'rows', 25),
order_by: _.get(options, 'order_by', 'timestamp'), order_by: _.get(options, 'order_by', 'timestamp'),
order_by_direction: 'desc' order_by_direction: 'desc',
no_count: true,
page: _.get(options, 'page', 1),
rows: _.get(options, 'rows', 25)
}; };
if(type !== null) { if (type !== null) {
params.type = type; params.type = type;
} }
getList({ getList({
path: 'api/conversations/', path: 'api/conversations/',
root: '_embedded.ngcp:conversations', root: '_embedded.ngcp:conversations',
params: params params: params,
all: false
}).then((list)=>{ }).then((list)=>{
resolve(list); resolve(list);
}).catch((err)=>{ }).catch((err)=>{

@ -41,7 +41,7 @@
/> />
</q-tabs> </q-tabs>
<q-list <q-list
v-if="!isNextPageRequesting && items.length > 0" v-if="items.length > 0"
no-border no-border
inset-separator inset-separator
sparse sparse
@ -196,7 +196,7 @@
if(!this.isNextPageRequesting && !this.scrollEventEmitted && data.direction === 'down' && if(!this.isNextPageRequesting && !this.scrollEventEmitted && data.direction === 'down' &&
data.position > scroll.getScrollHeight(this.$refs.page.$el) - window.innerHeight + 30) { data.position > scroll.getScrollHeight(this.$refs.page.$el) - window.innerHeight + 30) {
this.scrollEventEmitted = true; this.scrollEventEmitted = true;
this.nextPage(); this.nextPage(this.selectedTab);
} }
else if(data.position <= scroll.getScrollHeight(this.$refs.page.$el) - window.innerHeight + 30) { else if(data.position <= scroll.getScrollHeight(this.$refs.page.$el) - window.innerHeight + 30) {
this.scrollEventEmitted = false; this.scrollEventEmitted = false;

@ -58,7 +58,7 @@ export default {
playVoiceMailStates: {}, playVoiceMailStates: {},
playVoiceMailErrors: {}, playVoiceMailErrors: {},
currentPage: 0, currentPage: 0,
lastPage: null, reachedLastPage: false,
nextPageState: RequestState.initiated, nextPageState: RequestState.initiated,
nextPageError: null, nextPageError: null,
items: [], items: [],
@ -88,8 +88,8 @@ export default {
currentPage(state) { currentPage(state) {
return state.currentPage; return state.currentPage;
}, },
lastPage(state) { isLastPage(state) {
return state.lastPage; return state.reachedLastPage;
}, },
rowsAlreadyLoaded(state) { rowsAlreadyLoaded(state) {
return state.items.length; return state.items.length;
@ -174,7 +174,7 @@ export default {
resetList(state) { resetList(state) {
state.items = []; state.items = [];
state.currentPage = 0; state.currentPage = 0;
state.lastPage = null; state.reachedLastPage = false;
}, },
nextPageRequesting(state) { nextPageRequesting(state) {
state.nextPageState = RequestState.requesting; state.nextPageState = RequestState.requesting;
@ -184,7 +184,7 @@ export default {
state.nextPageState = RequestState.succeeded; state.nextPageState = RequestState.succeeded;
state.nextPageError = null; state.nextPageError = null;
state.items = state.items.concat(items.items); state.items = state.items.concat(items.items);
state.lastPage = items.lastPage; state.reachedLastPage = items.items.length === 0;
state.currentPage = state.currentPage + 1; state.currentPage = state.currentPage + 1;
linkCallsWithSameId(state); linkCallsWithSameId(state);
}, },
@ -252,12 +252,11 @@ export default {
}); });
}, },
nextPage(context, type) { nextPage(context, type) {
let page = context.getters.currentPage + 1; if (!context.getters.isLastPage) {
if(context.getters.lastPage === null || page <= context.getters.lastPage) {
context.commit('nextPageRequesting'); context.commit('nextPageRequesting');
getConversations({ getConversations({
subscriberId: context.getters.getSubscriberId, subscriberId: context.getters.getSubscriberId,
page: page, page: context.getters.currentPage + 1,
rows: ROWS_PER_PAGE, rows: ROWS_PER_PAGE,
type: type type: type
}).then((result) => { }).then((result) => {

Loading…
Cancel
Save