Commit 9b6a6ca7 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩
Browse files

Improve import friends from vcard time by bypassing a few checks + added test...

Improve import friends from vcard time by bypassing a few checks + added test to calculate 1000 vcards import time
parent 79086201
......@@ -508,28 +508,32 @@ LinphoneFriend * linphone_core_create_friend_with_address(LinphoneCore *lc, cons
return linphone_friend_new_with_address(address);
}
void linphone_core_add_friend(LinphoneCore *lc, LinphoneFriend *lf)
{
ms_return_if_fail(lf->lc==NULL);
ms_return_if_fail(lf->uri!=NULL);
if (ms_list_find(lc->friends,lf)!=NULL){
char *tmp=NULL;
const LinphoneAddress *addr=linphone_friend_get_address(lf);
if (addr) tmp=linphone_address_as_string(addr);
void linphone_core_add_friend(LinphoneCore *lc, LinphoneFriend *lf) {
ms_return_if_fail(!lf->lc);
if (!lf->uri) {
return; // Do not abort if friend doesn't have a SIP URI
}
if (ms_list_find(lc->friends, lf)) {
char *tmp = NULL;
const LinphoneAddress *addr = linphone_friend_get_address(lf);
if (addr) tmp = linphone_address_as_string(addr);
ms_warning("Friend %s already in list, ignored.", tmp ? tmp : "unknown");
if (tmp) ms_free(tmp);
return ;
return;
}
lc->friends=ms_list_append(lc->friends,linphone_friend_ref(lf));
if (ms_list_find(lc->subscribers, lf)){
linphone_core_import_friend(lc, lf);
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);
linphone_friend_unref(lf);
}
lf->lc=lc;
if ( linphone_core_ready(lc)) linphone_friend_apply(lf,lc);
else lf->commit=TRUE;
return ;
}
void linphone_core_import_friend(LinphoneCore *lc, LinphoneFriend *lf) {
lc->friends = ms_list_append(lc->friends, linphone_friend_ref(lf));
if (linphone_core_ready(lc)) linphone_friend_apply(lf, lc);
else lf->commit = TRUE;
}
void linphone_core_remove_friend(LinphoneCore *lc, LinphoneFriend* fl){
......
......@@ -1399,6 +1399,8 @@ bool_t linphone_core_lime_for_file_sharing_enabled(const LinphoneCore *lc);
BELLE_SIP_DECLARE_VPTR(LinphoneTunnelConfig);
int linphone_core_get_default_proxy_config_index(LinphoneCore *lc);
void linphone_core_import_friend(LinphoneCore *lc, LinphoneFriend *lf);
#ifdef __cplusplus
}
......
......@@ -72,7 +72,7 @@ RCFILES = \
IMAGE_FILES = images/nowebcamCIF.jpg
COMMON_FILE = common/bc_completion common/vcards.vcf
COMMON_FILE = common/bc_completion common/vcards.vcf common/thousand_vcards.vcf
EXTRA_DIST = tester_hosts\
messages.db\
......
This diff is collapsed.
......@@ -20,6 +20,8 @@
#include "private.h"
#include "liblinphone_tester.h"
#include <time.h>
static char *create_filepath(const char *dir, const char *filename, const char *ext) {
return ms_strdup_printf("%s/%s.%s", dir, filename, ext);
}
......@@ -52,8 +54,25 @@ static void linphone_vcard_import_export_friends_test(void) {
linphone_core_manager_destroy(manager);
}
static void linphone_vcard_import_a_lot_of_friends_test(void) {
LinphoneCoreManager* manager = linphone_core_manager_new2("empty_rc", FALSE);
char *import_filepath = bc_tester_res("common/thousand_vcards.vcf");
clock_t start, end;
double elapsed = 0;
start = clock();
linphone_core_import_friends_from_vcard4_file(manager->lc, import_filepath);
end = clock();
elapsed = (double)(end - start);
ms_error("Imported a thousand of friends in %f seconds", elapsed / CLOCKS_PER_SEC);
BC_ASSERT_TRUE(elapsed < 2500000); // 2.5 seconds
linphone_core_manager_destroy(manager);
}
test_t vcard_tests[] = {
{ "Import / Export friends from vCards", linphone_vcard_import_export_friends_test },
{ "Import a lot of friends from vCards", linphone_vcard_import_a_lot_of_friends_test },
};
test_suite_t vcard_test_suite = {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment