Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop recreating related items on every save #2179

Closed
antonioribeiro opened this issue Mar 13, 2023 · 0 comments · Fixed by #2198
Closed

Stop recreating related items on every save #2179

antonioribeiro opened this issue Mar 13, 2023 · 0 comments · Fixed by #2198

Comments

@antonioribeiro
Copy link
Member

Summary

Blocks and browsers when connected to related items make use of this code:

public function saveRelated($items, $browser_name)
{
    $this->clearRelated($browser_name);

    $position = 1;

    Collection::make($items)->map(function ($item) {
        return Arr::only($item, ['endpointType', 'id']);
    })->each(function ($values) use ($browser_name, &$position) {
        RelatedItem::create([
            'subject_id' => $this->getKey(),
            'subject_type' => $this->getMorphClass(),
            'related_id' => $values['id'],
            'related_type' => $values['endpointType'],
            'browser_name' => $browser_name,
            'position' => $position,
        ]);
        $position++;
    });
}

Not only this increases the number of dead rows on the related table, by deleting then recreating them every time, but, when nothing changed on a module, it also gives the false impression something has changed, as Laravel will fire eloquent.created events for these changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant