Remove the locking to improve performance
This commit is contained in:
parent
87f054a642
commit
84d8753d5f
|
@ -609,8 +609,6 @@ class GContact
|
|||
*/
|
||||
public static function getId($contact)
|
||||
{
|
||||
$gcontact_id = 0;
|
||||
|
||||
if (empty($contact['network'])) {
|
||||
Logger::notice('Empty network', ['url' => $contact['url'], 'callstack' => System::callstack()]);
|
||||
return false;
|
||||
|
@ -630,12 +628,12 @@ class GContact
|
|||
$contact['url'] = self::cleanContactUrl($contact['url']);
|
||||
}
|
||||
|
||||
DBA::lock('gcontact');
|
||||
$fields = ['id', 'last_contact', 'last_failure', 'network'];
|
||||
$gcnt = DBA::selectFirst('gcontact', $fields, ['nurl' => Strings::normaliseLink($contact['url'])]);
|
||||
if (DBA::isResult($gcnt)) {
|
||||
$gcontact_id = $gcnt['id'];
|
||||
} else {
|
||||
$condition = ['nurl' => Strings::normaliseLink($contact['url'])];
|
||||
$gcontact = DBA::selectFirst('gcontact', ['id'], $condition, ['order' => ['id']]);
|
||||
if (DBA::isResult($gcontact)) {
|
||||
return $gcontact['id'];
|
||||
}
|
||||
|
||||
$contact['location'] = $contact['location'] ?? '';
|
||||
$contact['about'] = $contact['about'] ?? '';
|
||||
$contact['generation'] = $contact['generation'] ?? 0;
|
||||
|
@ -648,15 +646,14 @@ class GContact
|
|||
|
||||
DBA::insert('gcontact', $fields);
|
||||
|
||||
$condition = ['nurl' => Strings::normaliseLink($contact['url'])];
|
||||
$cnt = DBA::selectFirst('gcontact', ['id', 'network'], $condition, ['order' => ['id']]);
|
||||
if (DBA::isResult($cnt)) {
|
||||
$gcontact_id = $cnt['id'];
|
||||
// We intentionally aren't using lastInsertId here. There is a chance for duplicates.
|
||||
$gcontact = DBA::selectFirst('gcontact', ['id'], $condition, ['order' => ['id']]);
|
||||
if (!DBA::isResult($gcontact)) {
|
||||
Logger::info('GContact creation failed', $fields);
|
||||
// Shouldn't happen
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
DBA::unlock();
|
||||
|
||||
return $gcontact_id;
|
||||
return $gcontact['id'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue