Skip to content

Conversation

@juliusknorr
Copy link
Member

Add ETag to NavigationController and return proper not modified status.

For nextcloud/desktop#195

$navigation = $this->rewriteToAbsoluteUrls($navigation);
}
return new DataResponse($navigation);
$etag = md5(json_encode($navigation));
Copy link
Member

Choose a reason for hiding this comment

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

I get everytime a new etag, because the logout URL is dynamic:

[
    {
        "type": "settings",
        "id": "settings",
        "order": 1,
        "href": "/index.php/settings/user",
        "name": "Einstellungen",
        "icon": "/settings/img/admin.svg",
        "active": false,
        "classes": ""
    },
    {
        "type": "settings",
        "id": "core_apps",
        "order": 3,
        "href": "/index.php/settings/apps",
        "icon": "/settings/img/apps.svg",
        "name": "Apps",
        "active": false,
        "classes": ""
    },
    {
        "type": "settings",
        "id": "core_users",
        "order": 4,
        "href": "/index.php/settings/users",
        "name": "Benutzer",
        "icon": "/settings/img/users.svg",
        "active": false,
        "classes": ""
    },
    {
        "type": "settings",
        "id": "help",
        "order": 5,
        "href": "/index.php/settings/help",
        "name": "Hilfe",
        "icon": "/settings/img/help.svg",
        "active": false,
        "classes": ""
    },
    {
        "type": "settings",
        "id": "logout",
        "order": 99999,
        "href": "http://localhost:8000/index.php/logout?requesttoken=0uDLjqUDfmx/MzvQzZhbmOqIlhEksOYx10axFnRuTI4%3D%3AhKiJwulSCwgMBhCz//8P7N6%2B/0BDgJ50sgXfTBMhNuc%3D",
        "name": "Abmelden",
        "icon": "/core/img/actions/logout.svg",
        "active": false,
        "classes": ""
    }
]

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh right, thanks. I've pushed a fix to just use the list of 'id' entries to generate the ETag.

@codecov
Copy link

codecov bot commented Mar 5, 2018

Codecov Report

Merging #8652 into master will decrease coverage by 16.81%.
The diff coverage is 0%.

@@              Coverage Diff              @@
##             master    #8652       +/-   ##
=============================================
- Coverage     51.81%   34.99%   -16.82%     
- Complexity    25354    25366       +12     
=============================================
  Files          1606     1606               
  Lines         95077    95101       +24     
  Branches       1378     1378               
=============================================
- Hits          49260    33284    -15976     
- Misses        45817    61817    +16000
Impacted Files Coverage Δ Complexity Δ
core/Controller/NavigationController.php 0% <0%> (-100%) 21 <6> (+12)
lib/private/BackgroundJob/QueuedJob.php 0% <0%> (-100%) 1% <0%> (ø)
...eware/Security/Exceptions/NotLoggedInException.php 0% <0%> (-100%) 1% <0%> (ø)
lib/private/App/AppStore/Bundles/Bundle.php 0% <0%> (-100%) 2% <0%> (ø)
core/Controller/ContactsMenuController.php 0% <0%> (-100%) 4% <0%> (ø)
apps/user_ldap/lib/Settings/Section.php 0% <0%> (-100%) 5% <0%> (ø)
lib/public/AppFramework/Http/StreamResponse.php 0% <0%> (-100%) 6% <0%> (ø)
lib/private/Security/IdentityProof/Key.php 0% <0%> (-100%) 3% <0%> (ø)
apps/files/lib/Activity/Settings/FileChanged.php 0% <0%> (-100%) 8% <0%> (ø)
...lib/Middleware/Exceptions/NotSubAdminException.php 0% <0%> (-100%) 1% <0%> (ø)
... and 526 more

}
return new DataResponse($navigation);

$etag = md5(json_encode(array_column($navigation, 'id')));
Copy link
Member

@MorrisJobke MorrisJobke Mar 5, 2018

Choose a reason for hiding this comment

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

But now changed names (especially for external sites entries) or changed URLs don't trigger anymore. I would just have a blacklist of entries that get cleared because they basically kill the etag and remove them before generating the etag.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, makes sense. Fixed.

@juliusknorr juliusknorr force-pushed the navigation-controller-etag branch from ec91e9c to 6e4424c Compare March 6, 2018 08:45
@juliusknorr juliusknorr force-pushed the navigation-controller-etag branch from 6e4424c to 11b6cc3 Compare March 6, 2018 08:51
Copy link
Member

@MorrisJobke MorrisJobke left a comment

Choose a reason for hiding this comment

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

Tested and works 👍

@MorrisJobke
Copy link
Member

CI fails, for example:

1) Tests\Core\Controller\NavigationControllerTest::testGetAppNavigationEtagMatch
Failed asserting that 200 matches expected 304.

@MorrisJobke MorrisJobke added 2. developing Work in progress and removed 3. to review Waiting for reviews labels Mar 6, 2018
Signed-off-by: Julius Härtl <[email protected]>
@MorrisJobke MorrisJobke added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Mar 7, 2018
@MorrisJobke MorrisJobke merged commit 3156d95 into master Mar 7, 2018
@MorrisJobke MorrisJobke deleted the navigation-controller-etag branch March 7, 2018 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review Waiting for reviews enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants