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

Added assigned components to assets API #10124

Merged
merged 3 commits into from
Sep 24, 2021

Conversation

snipe
Copy link
Owner

@snipe snipe commented Sep 24, 2021

By including components=true to the API request, we can now load the associated components. I'm not 100% sure here whether load(), loadMissing(), or with()` will be more performative, but the resulting JSON looks like this:

{
    "id": 1358,
    "name": "",
    "asset_tag": "148671489",
    "serial": "d52c24bd-e6eb-30e5-804f-935d28a304b7",
    "model": {
        "id": 17,
        "name": "Ultrafine 4k"
    },
    "model_number": "341423500614500",
    "eol": {
        "date": "2021-10-09",
        "formatted": "Sat Oct 09, 2021"
    },
    "status_label": {
        "id": 1,
        "name": "Ready to Deploy",
        "status_type": "deployable",
        "status_meta": "deployed"
    },
    "category": {
        "id": 5,
        "name": "Displays"
    },
    "manufacturer": {
        "id": 7,
        "name": "LG"
    },
    "supplier": {
        "id": 1,
        "name": "Cummings-Satterfield"
    },
    "notes": "Created by DB seeder",
    "order_number": "44946029",
    "company": null,
    "location": {
        "id": 5,
        "name": "East Ineston"
    },
    "rtd_location": {
        "id": 8,
        "name": "South Margaritafort"
    },
    "image": "https://snipe-it.local:8890/uploads/models/ultrafine.jpg",
    "assigned_to": {
        "id": 4,
        "username": "okon.jaiden",
        "name": "Serena Cruickshank",
        "first_name": "Serena",
        "last_name": "Cruickshank",
        "employee_number": "30291",
        "type": "user"
    },
    "warranty_months": null,
    "warranty_expires": null,
    "created_at": {
        "datetime": "2021-09-20 21:25:04",
        "formatted": "Mon Sep 20, 2021 9:25PM"
    },
    "updated_at": {
        "datetime": "2021-09-20 21:25:20",
        "formatted": "Mon Sep 20, 2021 9:25PM"
    },
    "last_audit_date": null,
    "next_audit_date": null,
    "deleted_at": null,
    "purchase_date": {
        "date": "2020-10-09",
        "formatted": "Fri Oct 09, 2020"
    },
    "last_checkout": null,
    "expected_checkin": null,
    "purchase_cost": "906.37",
    "checkin_counter": 0,
    "checkout_counter": 0,
    "requests_counter": 0,
    "user_can_checkout": false,
    "custom_fields": [],
    "components": [
        [
            {
                "id": 2,
                "name": "Crucial 8GB DDR3L-1600 SODIMM Memory for Mac",
                "qty": 1,
                "price_cost": "48.35",
                "purchase_total": 48.35,
                "checkout_date": {
                    "datetime": "2021-09-23 19:04:10",
                    "formatted": "Thu Sep 23, 2021 7:04PM"
                }
            }
        ],
        [
            {
                "id": 2,
                "name": "Crucial 8GB DDR3L-1600 SODIMM Memory for Mac",
                "qty": 1,
                "price_cost": "48.35",
                "purchase_total": 48.35,
                "checkout_date": {
                    "datetime": "2021-09-23 19:09:06",
                    "formatted": "Thu Sep 23, 2021 7:09PM"
                }
            }
        ],
        [
            {
                "id": 3,
                "name": "Crucial BX300 120GB SATA Internal SSD",
                "qty": 4,
                "price_cost": "13.21",
                "purchase_total": 52.84,
                "checkout_date": {
                    "datetime": "2021-09-23 19:09:16",
                    "formatted": "Thu Sep 23, 2021 7:09PM"
                }
            }
        ]
    ],
    "available_actions": {
        "checkout": true,
        "checkin": true,
        "clone": true,
        "restore": false,
        "update": true,
        "delete": false
    }
}

By only requesting this on demand, it allows us to exclude it from the regular API calls (and therefore not bog down the queries, which are already doing a LOT of relationship loading.)

Signed-off-by: snipe <snipe@snipe.net>
Signed-off-by: snipe <snipe@snipe.net>
Copy link
Collaborator

@uberbrady uberbrady left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great to me! If there’s a way to use the Laravel debug console thingee and watch the queries that fire across, and it’s the right ones, then it works good to me!

@snipe
Copy link
Owner Author

snipe commented Sep 24, 2021

Thanks Brady! Yeah, on my local, the numbers and type of queries (with eager loading) were behaving as I was expecting.

Now go back to your vacation, nerd! :D

@snipe snipe merged commit 53334f7 into master Sep 24, 2021
@snipe snipe deleted the features/added_components_to_assets_API branch September 24, 2021 01:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants