Repository: microsoft/PowerToys
File: src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Commands/MainListPage.cs (C#)

Code before:

                if (token.IsCancellationRequested)
                {
                    return;
                }
            }

            var history = _serviceProvider.GetService<AppStateModel>()!.RecentCommands!;
            Func<string, IListItem, int> scoreItem = (a, b) => { return ScoreTopLevelItem(a, b, history); };

            // Produce a list of everything that matches the current filter.
            _filteredItems = [.. ListHelpers.FilterListWithScores<IListItem>(newFilteredItems ?? [], SearchText, scoreItem)];

            if (token.IsCancellationRequested)
            {
                return;
            }

            IEnumerable<IListItem> newFallbacksForScoring = commands.Where(s => s.IsFallback && _specialFallbacks.Contains(s.CommandProviderId));

            if (token.IsCancellationRequested)
            {
                return;
            }

            _scoredFallbackItems = [.. ListHelpers.FilterListWithScores<IListItem>(newFallbacksForScoring ?? [], SearchText, scoreItem)];

            if (token.IsCancellationRequested)
            {
                return;
            }

            // Defaulting scored to 1 but we'll eventually use user rankings
            _fallbackItems = [.. newFallbacks.Select(f => new Scored<IListItem> { Item = f, Score = 1 })];

            if (token.IsCancellationRequested)
            {
                return;
            }

            // Produce a list of filtered apps with the appropriate limit
            if (newApps.Any())
            {
                var scoredApps = ListHelpers.FilterListWithScores<IListItem>(newApps, SearchText, scoreItem);

                if (token.IsCancellationRequested)
                {
                    return;
                }

                // We'll apply this limit in the GetItems method after merging with commands

Review comment (suggestion):
This has to be materialized in GetItems. `UpdateFallbacks` method runs a code on a background task that updates the texts and then raises change notification which leads to `GetItems` being called.

Code after:
                        newApps = allNewApps;
                    }
                }

                if (token.IsCancellationRequested)
                {
                    return;
                }
            }

            var history = _serviceProvider.GetService<AppStateModel>()!.RecentCommands!;
            Func<string, IListItem, int> scoreItem = (a, b) => { return ScoreTopLevelItem(a, b, history); };

            // Produce a list of everything that matches the current filter.
            _filteredItems = [.. ListHelpers.FilterListWithScores<IListItem>(newFilteredItems ?? [], SearchText, scoreItem)];

            if (token.IsCancellationRequested)
            {
                return;
            }

            IEnumerable<IListItem> newFallbacksForScoring = commands.Where(s => s.IsFallback && _specialFallbacks.Contains(s.CommandProviderId));

            if (token.IsCancellationRequested)
            {
                return;
            }

            _scoredFallbackItems = ListHelpers.FilterListWithScores<IListItem>(newFallbacksForScoring ?? [], SearchText, scoreItem);

            if (token.IsCancellationRequested)
            {
                return;
            }

            // Defaulting scored to 1 but we'll eventually use user rankings
            _fallbackItems = [.. newFallbacks.Select(f => new Scored<IListItem> { Item = f, Score = 1 })];

            if (token.IsCancellationRequested)
            {
                return;
            }

            // Produce a list of filtered apps with the appropriate limit
            if (newApps.Any())
            {
                var scoredApps = ListHelpers.FilterListWithScores<IListItem>(newApps, SearchText, scoreItem);

                if (token.IsCancellationRequested)
                {
                    return;