Commit Graph

28 Commits

Author SHA1 Message Date
Jason Novinger
fb004bb94e
#20327: Device queries now faster when including ConfigContexts (#20346)
* Fixes #20327: Device queries are now faster when including ConfidContexts
Move .distinct() from main queryset to tag subquery to eliminate
performance bottleneck when querying devices with config contexts.

The .distinct() call on the main device queryset was causing PostgreSQL
to sort all devices before pagination, resulting in 15x slower API
responses for large installations (10k+ devices, 100+ config contexts).

Moving .distinct() to the tag subquery eliminates duplicates at their
source (GenericForeignKey tag relationships) while preserving the fix
for issues #5314 and #5387 without impacting overall query performance.

* Add performance regression test for config context annotation

The test verifies that:
- Main device queries do not use expensive DISTINCT operations
- Tag subqueries properly use DISTINCT to prevent duplicates from issue #5387

This ensures the optimization from issue #20327 (moving .distinct() from maintaining
query to tag subquery) cannot be accidentally reverted while maintaining the
correctness guarantees for issues #5314 and #5387.

* Address PR feedback, clean up new regression test

The new regression test now avoids casting the query to a string and
inspecting the string, which was brittle at best.

The new approach asserts directly against `queryset.distinct` for the
main query and then finds the subquery that we expect to have distinct
set and verifies that is in fact the case.

I also realized that the use of `connection.query_log` was problematic,
in that it didn't seem to return any queries as expected. This meant
that the test was actually not making any assertions since none of the
code inside of the for loop over `device_queries` ever ran.
2025-09-15 13:04:56 -04:00
Martin Hauser
2d6b3d19e7
Fixes #20236: Improve file naming and upload handling (#20315)
Some checks are pending
CI / build (20.x, 3.10) (push) Waiting to run
CI / build (20.x, 3.11) (push) Waiting to run
CI / build (20.x, 3.12) (push) Waiting to run
CodeQL / Analyze (${{ matrix.language }}) (none, actions) (push) Waiting to run
CodeQL / Analyze (${{ matrix.language }}) (none, javascript-typescript) (push) Waiting to run
CodeQL / Analyze (${{ matrix.language }}) (none, python) (push) Waiting to run
2025-09-12 17:41:49 -05:00
Jeremy Stretch
b4c88541da
Closes #19377: Introduce config context profiles (#20058)
Some checks failed
CodeQL / Analyze (${{ matrix.language }}) (none, python) (push) Has been cancelled
CodeQL / Analyze (${{ matrix.language }}) (none, actions) (push) Has been cancelled
CodeQL / Analyze (${{ matrix.language }}) (none, javascript-typescript) (push) Has been cancelled
CI / build (20.x, 3.10) (push) Has been cancelled
CI / build (20.x, 3.11) (push) Has been cancelled
CI / build (20.x, 3.12) (push) Has been cancelled
2025-08-12 15:18:45 -07:00
Jason Novinger
d7672ab260 Fixes #19490: restores nesting behavior of DataSource-based ConfigTemplates
The ability to render nested templates was accidentally removed with the
implementation of #17653, which normalized the behavior of various Jinja2
template rendering actions.

This fix restores that behavior while retaining the normalized behavior.
This fix also includes regression tests to ensure this behavior is not
removed accidentally again in the future.
2025-05-23 16:34:22 -05:00
Jeremy Stretch
d55f02b25f
#14591, #17841: Adjust default weighting (#19155)
* #14591, #17841: Adjust default weighting

* Fix tests
2025-04-11 14:27:55 -05:00
Jeremy Stretch
fc0acb020f Merge main into feature 2025-04-10 17:17:21 -04:00
Jason Novinger
6b7d23d684
Closes #17841 Allows Tags to be displayed in specified order (#18930) 2025-03-19 10:17:35 -07:00
Arthur Hanson
6dc75d8db1
7699 Add Scope to Cluster (#17848)
* 7699 Add Scope to Cluster

* 7699 Serializer

* 7699 filterset

* 7699 bulk_edit

* 7699 bulk_import

* 7699 model_form

* 7699 graphql, tables

* 7699 fixes

* 7699 fixes

* 7699 fixes

* 7699 fixes

* 7699 fix tests

* 7699 fix graphql tests for clusters reference

* 7699 fix dcim tests

* 7699 fix ipam tests

* 7699 fix tests

* 7699 use mixin for model

* 7699 change mixin name

* 7699 scope form

* 7699 scope form

* 7699 scoped form, fitlerset

* 7699 review changes

* 7699 move ScopedFilterset

* 7699 move CachedScopeMixin

* 7699 review changes

* 7699 review changes

* 7699 refactor mixins

* 7699 _sitegroup -> _site_group

* 7699 update docstring

* Misc cleanup

* Update migrations

---------

Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
2024-11-01 14:18:23 -04:00
Jeremy Stretch
7ac6dff96d
Closes #17733: Replace pycodestyle with ruff (#17734)
* Resolve F541 errors

* Resolve F841 errors

* Resolve F811 errors

* Resolve F901 errors

* Resolve E714 errors

* Ignore F821 errors for GraphQL mixins

* Replace pycodestyle with ruff

* Move ignores to ruff.toml
2024-10-11 07:43:46 -04:00
Jeremy Stretch
570f64784f Update Tag.object_types to reference ObjectType 2024-03-04 09:51:32 -05:00
ChrisPortman
59510b4bd0
Issue #14962 VM to merge directly related site context (#14992)
* Issue #14962 VM to merge directly related site context

* Cleanup & rewrite test

---------

Co-authored-by: Chris Carter <chris.carter@spinlocksecurity.com>
Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
2024-02-02 10:16:07 -05:00
Abhimanyu Saharan
0bb86f1e7d
Replaces device_role with role on device model (#13342)
* replaces device_role with role on device model #6391

* fixes lint issue #6391

* revert the database user

* revert test_runner comment

* changes as per review

* Update references to device_role column in UserConfigs

---------

Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
2023-08-02 09:55:52 -04:00
Jeremy Stretch
1056e513b1
Closes #11541: Support for limiting tag assignments by object type (#12982)
* Initial work on #11541

* Merge migrations

* Limit tags by object type during assignment

* Add tests for object type validation

* Fix form field parameters
2023-06-23 14:08:14 -04:00
jeremystretch
d4a231585a Clean up tests 2022-11-17 10:50:05 -05:00
jeremystretch
379880cd84 Closes #9582: Enable assigning config contexts based on device location 2022-06-22 16:10:48 -04:00
jeremystretch
77dd684916 Closes #7784: Support cluster type assignment for config contexts 2021-12-23 14:20:03 -05:00
Jeremy Stretch
bfa95c16e3 Add missing tests for SiteGroup 2021-03-30 11:06:59 -04:00
Jeremy Stretch
a371c08c86 Merge branch 'develop' into develop-2.10 2020-12-11 16:57:04 -05:00
John Anderson
53f330dbe8
fixes #5387 - Fix error when rendering config contexts when objects have multiple tags assigned (#5447) 2020-12-11 16:20:46 -05:00
Jeremy Stretch
0567f0d190 Merge branch 'develop' into develop-2.10 2020-11-09 20:58:59 -05:00
John Anderson
0d27abc6fc fixes #5314 - Fix config context rendering when multiple tags are assgined to an object 2020-11-06 16:47:07 -05:00
Jeremy Stretch
fcb5e6ae1c Merge branch 'develop' into develop-2.10 2020-10-30 10:38:05 -04:00
John Anderson
26ff33c41a pep8 2020-10-25 17:56:42 -04:00
John Anderson
9e84e3b83b added tests 2020-10-25 16:49:18 -04:00
Jeremy Stretch
ec66e1a5c0 Closes #4349: Drop support for embedded graphs 2020-08-21 11:57:46 -04:00
Jeremy Stretch
606f3dacbb Fixes #3721: Allow Unicode characters in tag slugs 2020-01-17 17:25:46 -05:00
Jeremy Stretch
deec10efe7 Rename ExportTemplateLanguageChoices to TemplateLanguageChoices 2020-01-15 09:40:05 -05:00
Jeremy Stretch
123a58bf7d Add tests for Graph rendering 2020-01-10 11:51:14 -05:00