Skip to content

Commit

Permalink
pkp#10948 Optimize delete query and resequence at vocab insertion
Browse files Browse the repository at this point in the history
  • Loading branch information
touhidurabir committed Feb 19, 2025
1 parent fe56411 commit 346ea85
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions classes/controlledVocab/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,14 @@ public function insertBySymbolic(
): void
{
$controlledVocab = $this->build($symbolic, $assocType, $assocId);
$controlledVocab->load('controlledVocabEntries');
$controlledVocabEntry = new ControlledVocabEntry;
$controlledVocabEntrySettings = $controlledVocabEntry->getSettings();
$multilingualProps = array_flip($controlledVocabEntry->getMultilingualProps());
$idKey = ControlledVocabEntry::CONTROLLED_VOCAB_ENTRY_IDENTIFIER;
$srcKey = ControlledVocabEntry::CONTROLLED_VOCAB_ENTRY_SOURCE;

if ($deleteFirst) {
ControlledVocabEntry::query()
->whereIn(
(new ControlledVocabEntry)->getKeyName(),
$controlledVocab->controlledVocabEntries->pluck('id')->toArray()
)
->delete();
ControlledVocabEntry::query()->withControlledVocabId($controlledVocab->id)->delete();
}

collect($vocabs)
Expand All @@ -122,7 +116,11 @@ public function insertBySymbolic(
)
);

$this->resequence($controlledVocab->id);
// Only resequence at the time of insert when `$deleteFirst` set to false
// Otherwise all existing data will be deleted and sequenced at the time of insertion.
if (!$deleteFirst) {
$this->resequence($controlledVocab->id);
}
}

/**
Expand Down

0 comments on commit 346ea85

Please sign in to comment.