Getting number of projects from cli

I would like to get the number of projects on our GitLab into our metrics system. That would require a command returning (just) that.

I’ve found that I can get the number with sudo gitlab-rails runner 'puts Project.count', but that takes more than 22 seconds to execute on our gitlab server, which is a lot of time for something so simple, furthermore the number is available on the admin overview page, which generates a lot faster (so a script to fetch that, and scrape the info from there, would probably be faster, but also more complex and fragile), so the number must be somewhere?

I found a nasty way of doing it. If I request
https://localhost/api/v4/projects?per_page=1
the “X-Total-Pages:” give the number, and that only takes around 0,2 seconds to execute.