sourcegraph/src-cli

Improve performance of `src users clean` in instances with many users

Closed this issue · 2 comments

In instances with many users the graphQL request to get all users and compute their lastActiveUsage can timeout going over the network --

In the example below the command is used on an instance with 29 users, then pointed at an instance with 186, this shows an example of the failure.

warrengifford@Warrens-MacBook-Pro ~ % src users clean
Users to remove from instance at https://cse-k8s.sgdev.org
╭───────────────────┬──────────────────────────────────┬────────────────────────╮
│ USERNAME          │ EMAIL                            │ DAYS SINCE LAST ACTIVE │
├───────────────────┼──────────────────────────────────┼────────────────────────┤
│ sourcegraph       │ cs-integrations@sourcegraph.com  │                    302 │
├───────────────────┼──────────────────────────────────┼────────────────────────┤
│ g-bot             │ warrenbruceg@gmail.com           │                    282 │
├───────────────────┼──────────────────────────────────┼────────────────────────┤
│ testAtSourcegraph │ testAtSourcegraph@mailinator.com │                    253 │
├───────────────────┼──────────────────────────────────┼────────────────────────┤
│ Malo              │ malo@sourcegraph.com             │                    221 │
├───────────────────┼──────────────────────────────────┼────────────────────────┤
│ ErikSeliger       │ erik@sourcegraph.com             │                    191 │
├───────────────────┼──────────────────────────────────┼────────────────────────┤
│ support           │                                  │                    132 │
├───────────────────┼──────────────────────────────────┼────────────────────────┤
│ gab2              │                                  │                     64 │
╰───────────────────┴──────────────────────────────────┴────────────────────────╯
Do you  wish to proceed with user removal [y/N]: n
Aborting removal
warrengifford@Warrens-MacBook-Pro ~ % vim ~/.zshrc
warrengifford@Warrens-MacBook-Pro ~ % source ~/.zshrc
warrengifford@Warrens-MacBook-Pro ~ % src login

✔️  Authenticated as warren on https://k8s.sgdev.org

warrengifford@Warrens-MacBook-Pro ~ % src users clean
error: 504 Gateway Timeout

<html>
<head><title>504 Gateway Time-out</title></head>
<body>
<center><h1>504 Gateway Time-out</h1></center>
<hr><center>nginx</center>
</body>
</html>

This problem was foreseen in the original release PR by @mrnugget

Since then @mrnugget has added a new graphQL field that should improve performance here, and users clean needs to be rewritten to incorperate this more efficient query https://github.com/sourcegraph/sourcegraph/pull/42352/files

Working branch utilizing the new graphQL filter
https://github.com/sourcegraph/src-cli/tree/inactiveSinceClean

Still needing to handle for lastActiveUsage null users i.e. registered users who have never visited the site

Working Branch for improvements in inactiveSince graphQL filter: https://github.com/sourcegraph/sourcegraph/pull/43370/files