I'm working on fixing some major latency issues with our login process, and in doing a lot of logging to Identtiy Server 4, I found what looks like a duplicate set of queries being run on every login.
Does anyone with some experience with IS4 have any idea why this is happening or what can be done about it? The calls appear to be coming from the middleware of IS4, and not any of our custom code.
EDIT: I added some tracking in my database for queries, and found the following:
These sets of queries run about 7 times during the full login process. Other queries are run as well, but these in particular run seven times.
I'm new to using the query store this way, but my understanding of how the stored execution plans and data works, if a different parameter had been passed in, it would appear as a new line in one of the tables (either the query store or the query_store_plan). Since there is only one row per query in the query store, and one plan per row, my conclusion is that it is only looking for one particular client ID. We'll call that client 'AdminTool'
It seems highly inefficient to run the same query seven times during the login process. I'm sure some of that has to do with token generation and other things that the data can't be persisted across, but seven still seems excessive.
One sample query from the execution plan is:
SELECT [x.IdentityProviderRestrictions].[Id], [x.IdentityProviderRestrictions].[ClientId],
[x.IdentityProviderRestrictions].[Provider]
FROM [ClientIdPRestrictions] AS [x.IdentityProviderRestrictions]
INNER JOIN (SELECT TOP(1) [x6].[Id] FROM [Clients] AS [x6]
WHERE [x6].[ClientId] = @__clientId_0
ORDER BY [x6].[Id])
AS [t5]
ON [x.IdentityProviderRestrictions].[ClientId] = [t5].[Id]
ORDER BY [t5].[Id]
With the execution plan's parameter list including:
<ColumnReference Column="@__clientId_0" ParameterDataType="nvarchar(200)"
ParameterCompiledValue="N'AdminTool'" />