App Server GUI extremely slow after migration

I migrated a quite old setup to latest versions and after the migration everything regarding the GUI running on port 8080 is extremely slow. Migration was done first to latest 0.x versions, then to v1 and then to v2 latest via apt update. Between every step I let the services do the node/device migrations before continuing.
What might cause the delays?
Nothing in the lora* logs, but checking Postgre i found a few long-running queries for every action taken in the LoRa App Server GUI (shows 6 seconds, but have seen 30+seconds before the GUI responds):

27509  00:00:06.68679 loraserver_test
select count(*) from "user" u left join organization_user ou on = ou.user_id left join organization o on = ou.organization_id left join gateway g on = g.organization_id left join application a on a.organization_id = left join service_profile sp on sp.organization_id = left join device_profile dp on dp.organization_id = left join network_server ns on = sp.network_server_id or = dp.network_server_id left join device d on = d.application_id left join multicast_group mg on sp.service_profile_id = mg.service_profile_id where ((u.username = $1) and (u.is_active = true) and (u.is_admin = true)) or ((u.username = $1) and (u.is_active = true) and ( = $2))

View from the browser side:

edit: Creating a new global admin user seems to have solved it.

This is the log with admin user:
Feb 05 19:31:43 test-02 lora-app-server[2905]: time="2019-02-05T19:31:43+02:00" level=info msg="finished unary call with code OK" grpc.code=OK grpc.method=List grpc.service=api.DeviceService grpc.start_time="2019-02-05T19:31:01+02:00" grpc.time_ms=42031.617 peer.address="[::1]:35780" span.kind=server system=grpc

But this is with a new user made through GUI:
Feb 05 20:02:17 test-02 lora-app-server[2905]: time="2019-02-05T20:02:17+02:00" level=info msg="finished unary call with code OK" grpc.code=OK grpc.method=List grpc.service=api.ApplicationService grpc.start_time="2019-02-05T20:02:17+02:00" grpc.time_ms=25.97 peer.address="[::1]:35776" span.kind=server system=grpc

The same delay is in API as well, using a previously signed token for “admin” user, even the /api/users?limit=100 query takes 30+ seconds. Using a new token for a new user the query is almost instant. There are only 2 users. But approx 2400 devices.

Look at this in line 33 and 877.

select count(*)

to check for existance is rubbish.

select 1 … limit 1

does well in this case, but in millisecs.

Feel free to create a pull-request when you see possible improvements :slight_smile: