From bab0c39c6f690ef6f6e5df9988a9b87d00e855d5 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Thu, 17 Dec 2015 15:25:31 +0100 Subject: [PATCH] Improved import time by optimizing moment when friends are saved in rc file --- coreapi/friend.c | 42 ++++++++++++++++++++++++------------------ tester/vcard_tester.c | 2 +- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/coreapi/friend.c b/coreapi/friend.c index bc0341f15..21d218513 100644 --- a/coreapi/friend.c +++ b/coreapi/friend.c @@ -467,47 +467,51 @@ void linphone_friend_update_subscribes(LinphoneFriend *fr, LinphoneProxyConfig * } } -void linphone_friend_apply(LinphoneFriend *fr, LinphoneCore *lc){ +void linphone_friend_save(LinphoneFriend *fr, LinphoneCore *lc) { + linphone_core_write_friends_config(lc); +} + +void linphone_friend_apply(LinphoneFriend *fr, LinphoneCore *lc) { LinphonePresenceModel *model; - if (fr->uri==NULL) { + if (!fr->uri) { ms_warning("No sip url defined."); return; } - linphone_core_write_friends_config(lc); - - if (fr->inc_subscribe_pending){ - switch(fr->pol){ + if (fr->inc_subscribe_pending) { + switch(fr->pol) { case LinphoneSPWait: model = linphone_presence_model_new_with_activity(LinphonePresenceActivityOther, "Waiting for user acceptance"); - linphone_friend_notify(fr,model); + linphone_friend_notify(fr, model); linphone_presence_model_unref(model); break; case LinphoneSPAccept: - if (fr->lc!=NULL) - linphone_friend_notify(fr,fr->lc->presence_model); + if (fr->lc) + linphone_friend_notify(fr, fr->lc->presence_model); break; case LinphoneSPDeny: - linphone_friend_notify(fr,NULL); + linphone_friend_notify(fr, NULL); break; } - fr->inc_subscribe_pending=FALSE; + fr->inc_subscribe_pending = FALSE; + } + if (fr->lc) { + linphone_friend_update_subscribes(fr, NULL, linphone_core_should_subscribe_friends_only_when_registered(fr->lc)); } - if (fr->lc) - linphone_friend_update_subscribes(fr,NULL,linphone_core_should_subscribe_friends_only_when_registered(fr->lc)); ms_message("linphone_friend_apply() done."); - lc->bl_refresh=TRUE; - fr->commit=FALSE; + lc->bl_refresh = TRUE; + fr->commit = FALSE; } void linphone_friend_edit(LinphoneFriend *fr){ } void linphone_friend_done(LinphoneFriend *fr){ - ms_return_if_fail(fr!=NULL); - if (fr->lc==NULL) return; - linphone_friend_apply(fr,fr->lc); + ms_return_if_fail(fr); + if (!fr->lc) return; + linphone_friend_apply(fr, fr->lc); + linphone_friend_save(fr, fr->lc); } LinphoneFriend * linphone_core_create_friend(LinphoneCore *lc) { @@ -533,6 +537,7 @@ void linphone_core_add_friend(LinphoneCore *lc, LinphoneFriend *lf) { return; } linphone_core_import_friend(lc, lf); + linphone_friend_save(lf, lc); if (ms_list_find(lc->subscribers, lf)) { /*if this friend was in the pending subscriber list, now remove it from this list*/ lc->subscribers = ms_list_remove(lc->subscribers, lf); @@ -853,6 +858,7 @@ int linphone_core_import_friends_from_vcard4_file(LinphoneCore *lc, const char * } vcards = ms_list_next(vcards); } + linphone_core_write_friends_config(lc); return count; } diff --git a/tester/vcard_tester.c b/tester/vcard_tester.c index 46efdc0f2..a7294c1c4 100644 --- a/tester/vcard_tester.c +++ b/tester/vcard_tester.c @@ -68,7 +68,7 @@ static void linphone_vcard_import_a_lot_of_friends_test(void) { friends = linphone_core_get_friend_list(manager->lc); elapsed = (double)(end - start); ms_error("Imported a thousand of vCards (only %i friends with SIP address found) in %f seconds", ms_list_size(friends), elapsed / CLOCKS_PER_SEC); - BC_ASSERT_TRUE(elapsed < 5000000); // 5 seconds + BC_ASSERT_TRUE(elapsed < 1500000); // 1.5 seconds linphone_core_manager_destroy(manager); }