mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2026-09-14 23:32:57 -04:00
FE+BE: performance improvements
This commit is contained in:
1 parent
cff3ddfc38
commit
f52de6cbdc
23 files changed
+428
-31
No files matched your search
@@ -832,6 +832,18 @@ def api_devices_totals_named(payload=None):
|
||||
"connected", "down", "favorites", "new", "archived", "all", "my",
|
||||
"offline"
|
||||
]}
|
||||
}, {
|
||||
"name": "limit",
|
||||
"in": "query",
|
||||
"required": False,
|
||||
"description": "Max devices to return",
|
||||
"schema": {"type": "integer", "minimum": 1, "maximum": 1000}
|
||||
}, {
|
||||
"name": "offset",
|
||||
"in": "query",
|
||||
"required": False,
|
||||
"description": "Number of devices to skip",
|
||||
"schema": {"type": "integer", "minimum": 0}
|
||||
}],
|
||||
links={
|
||||
"GetOpenPorts": {
|
||||
@@ -859,8 +871,10 @@ def api_devices_totals_named(payload=None):
|
||||
)
|
||||
def api_devices_by_status(payload: DeviceListRequest = None):
|
||||
status = payload.status if payload else request.args.get("status")
|
||||
limit = payload.limit if payload else request.args.get("limit", type=int)
|
||||
offset = payload.offset if payload else request.args.get("offset", type=int)
|
||||
device_handler = DeviceInstance()
|
||||
return jsonify(device_handler.getByStatus(status))
|
||||
return jsonify(device_handler.getByStatus(status, limit, offset))
|
||||
|
||||
|
||||
@app.route('/devices/search', methods=['POST'])
|
||||
|
||||
@@ -12,7 +12,7 @@ from logger import mylog # noqa: E402 [flake8 lint suppression]
|
||||
from const import apiPath, NULL_EQUIVALENTS # noqa: E402 [flake8 lint suppression]
|
||||
from helper import ( # noqa: E402 [flake8 lint suppression]
|
||||
is_random_mac,
|
||||
get_number_of_children,
|
||||
count_children_by_parent_mac,
|
||||
format_ip_long,
|
||||
get_setting_value,
|
||||
)
|
||||
@@ -178,10 +178,11 @@ class Query(ObjectType):
|
||||
]
|
||||
|
||||
# Add dynamic fields to each device
|
||||
children_counts = count_children_by_parent_mac(devices_data)
|
||||
for device in devices_data:
|
||||
device["devIsRandomMac"] = 1 if is_random_mac(device["devMac"]) else 0
|
||||
device["devParentChildrenCount"] = get_number_of_children(
|
||||
device["devMac"], devices_data
|
||||
device["devParentChildrenCount"] = children_counts.get(
|
||||
device["devMac"].strip(), 0
|
||||
)
|
||||
# Return as string — IPv4 long values can exceed Int's signed 32-bit max (2,147,483,647)
|
||||
device["devIpLong"] = str(format_ip_long(device.get("devLastIP", "")))
|
||||
|
||||
@@ -265,6 +265,8 @@ class DeviceListRequest(BaseModel):
|
||||
"- offline: Devices not present in the last scan"
|
||||
)
|
||||
)
|
||||
limit: Optional[int] = Field(None, ge=1, le=1000, description="Max devices to return")
|
||||
offset: Optional[int] = Field(None, ge=0, description="Number of devices to skip")
|
||||
|
||||
|
||||
class DeviceListResponse(RootModel):
|
||||
|
||||
Reference in new issue
Block a user