#21330 optimize the assignment of tags when saving an object #214

Closed
opened 2026-04-05 16:23:02 +02:00 by MrUnknownDE · 0 comments
Owner

Originally created by @arthanson on 3/5/2026

Fixes: #21330

Taggit was causing N+1 queries here. Created a new NetBoxTaggableManager replacing the add function on taggit and generally follows what it does but does a single bulk-insert of all tags instead of one at a time. Also a small optimization on the serializer. Could probably be upstreamed into Taggit, will look at opening an optimization PR there.

Created a new site with 12 tag assignments - checking the POST Request:

main branch: 76 SQL queries
this branch: 29 SQL queries

Note: After adding site, with debug toolbar, go to the history menu, find the post request and choose 'switch' to that then look at SQL queries.

*Originally created by @arthanson on 3/5/2026* ### Fixes: #21330 Taggit was causing N+1 queries here. Created a new NetBoxTaggableManager replacing the add function on taggit and generally follows what it does but does a single bulk-insert of all tags instead of one at a time. Also a small optimization on the serializer. Could probably be upstreamed into Taggit, will look at opening an optimization PR there. Created a new site with 12 tag assignments - checking the POST Request: main branch: 76 SQL queries this branch: 29 SQL queries **Note:** After adding site, with debug toolbar, go to the history menu, find the post request and choose 'switch' to that then look at SQL queries.
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/netbox#214