Use cached ScriptModule objects in Scripts List view #11557

Open
opened 2025-12-29 21:46:43 +01:00 by adam · 3 comments
Owner

Originally created by @Nick-Gatti on GitHub (Sep 2, 2025).

NetBox version

v4.3.6

Feature type

Change to existing functionality

Proposed functionality

I'm testing switching over from local file storage of scripts to hosting in an S3 bucket, and noticed an immediate slowdown (~10s) when loading the ScriptListView. From what it looks like, it seems like the view accesses script modules to determine the classes each time it's loaded- which in this case now means that each file gets downloaded from S3 every time. The ScriptModule caches the scripts inside it- could we switch the ListView to access the cached values to avoid redownloading each time?

Use case

Would speed up loading the scripts view page significantly.

Database changes

No response

External dependencies

No response

Originally created by @Nick-Gatti on GitHub (Sep 2, 2025). ### NetBox version v4.3.6 ### Feature type Change to existing functionality ### Proposed functionality I'm testing switching over from local file storage of scripts to hosting in an S3 bucket, and noticed an immediate slowdown (~10s) when loading the ScriptListView. From what it looks like, it seems like the view accesses script modules to determine the classes each time it's loaded- which in this case now means that each file gets downloaded from S3 every time. The ScriptModule caches the scripts inside it- could we switch the ListView to access the cached values to avoid redownloading each time? ### Use case Would speed up loading the scripts view page significantly. ### Database changes _No response_ ### External dependencies _No response_
adam added the type: featurestatus: needs ownercomplexity: mediumnetbox labels 2025-12-29 21:46:43 +01:00
Author
Owner

@bctiemann commented on GitHub (Sep 4, 2025):

Worth looking into -- need however to ensure that the cache is refreshed whenever the script is changed.

@bctiemann commented on GitHub (Sep 4, 2025): Worth looking into -- need however to ensure that the cache is refreshed whenever the script is changed.
Author
Owner

@Nick-Gatti commented on GitHub (Sep 4, 2025):

Worth looking into -- need however to ensure that the cache is refreshed whenever the script is changed.

From what I can tell, this is already done with a post_save signal.

@Nick-Gatti commented on GitHub (Sep 4, 2025): > Worth looking into -- need however to ensure that the cache is refreshed whenever the script is changed. From what I can tell, this is already done with a [post_save signal](https://github.com/netbox-community/netbox/blob/ea50786b5c68af6ca7eca91cfde36f8211f6b44b/netbox/extras/models/scripts.py#L192).
Author
Owner

@ross-cello commented on GitHub (Sep 5, 2025):

The caching might not quite do what one fully expects at present.

If, for example, I change a class within the script (remove, add, rename), this often requires an Edit/Save in UI to propagate those changes on top of a datasource sync.
This at least appears to be the case with a directory datasource. Sync otherwise refreshes the content of said classes.

Looking at that link from @Nick-Gatti, does sync_classes need to be moved inside sync_data as well, or otherwise also called on a datasource sync?

EDIT: Just re-tested on v4.4.0. Still present (Prod is v4.3.2)
Recreated using below, manipulating the classes between syncs. We don't trigger the behaviour often, so have just lived with the workaround.

from extras.scripts import Script

class SomeClass(Script):
    class Meta:
        name = "Some Class"
    def run(self, data, commit):
        return "Nothing to see here. Move along!"

class SomeNewClass(Script):
    class Meta:
        name = "Some New Class"
    def run(self, data, commit):
        return "Nothing to see here. Move along!"
@ross-cello commented on GitHub (Sep 5, 2025): The caching might not quite do what one fully expects at present. If, for example, I change a class within the script (remove, add, rename), this often requires an Edit/Save in UI to propagate those changes on top of a datasource sync. This at least appears to be the case with a directory datasource. Sync otherwise refreshes the content of said classes. Looking at that link from @Nick-Gatti, does `sync_classes` need to be moved inside `sync_data` as well, or otherwise also called on a datasource sync? EDIT: Just re-tested on v4.4.0. Still present (Prod is v4.3.2) Recreated using below, manipulating the classes between syncs. We don't trigger the behaviour often, so have just lived with the workaround. ``` from extras.scripts import Script class SomeClass(Script): class Meta: name = "Some Class" def run(self, data, commit): return "Nothing to see here. Move along!" class SomeNewClass(Script): class Meta: name = "Some New Class" def run(self, data, commit): return "Nothing to see here. Move along!" ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11557