Repository: microsoft/PowerToys
File: src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.OneNote/Main.cs (C#)

Code before:
            {
                return new List<Result>(0);
            }

            // If there's cached results for this query, return immediately, otherwise wait for delayedExecution.
            var results = cache.Get<List<Result>>(query.Search);
            return results ?? Query(query, false);
        }

        /// <summary>
        /// Return a filtered list, based on the given query
        /// </summary>
        /// <param name="query">The query to filter the list</param>
        /// <param name="delayedExecution">False if this is the first pass through plugins, true otherwise. Slow plugins should run delayed.</param>
        /// <returns>A filtered list, can be empty when nothing was found</returns>
        public List<Result> Query(Query query, bool delayedExecution)
        {
            if (!delayedExecution || !_oneNoteInstalled || query is null || string.IsNullOrWhiteSpace(query.Search) || cache is null)
            {
                return new List<Result>(0);
            }

            // Get results from cache if they already exist for this query, otherwise query OneNote. Results will be cached for 1 day.
            var results = cache.GetOrAdd(query.Search, () =>
            {
                var pages = OneNoteProvider.FindPages(query.Search);

                return pages.Select(p => new Result
                {
                    IcoPath = _iconPath,
                    Title = p.Name,
                    QueryTextDisplay = p.Name,
                    SubTitle = @$"{p.Notebook.Name}\{p.Section.Name}",
                    Action = (_) =>
                    {
                        p.OpenInOneNote();
                        ShowOneNote();
                        return true;
                    },
                    ContextData = p,
                    ToolTipData = new ToolTipData(Name, @$"{p.Notebook.Name}\{p.Section.Name}\{p.Name}"),
                }).ToList();
            });

            return results;
        }

        /// <summary>
        /// Return the translated plugin title.
        /// </summary>
        /// <returns>A translated plugin title.</returns>

Review comment (performance):
Can we cache the page data instead of the results? If delay in PT is disabled there is a query for each character.¹ Or is it different on delayed execution?

¹) So we get a cache for a, b, c, ... which makes no sense and only fills memory.

Code after:
            {
                return new List<Result>(0);
            }

            // If there's cached results for this query, return immediately, otherwise wait for delayedExecution.
            var results = _cache.Get<List<Result>>(query.Search);
            return results ?? Query(query, false);
        }

        /// <summary>
        /// Return a filtered list, based on the given query
        /// </summary>
        /// <param name="query">The query to filter the list</param>
        /// <param name="delayedExecution">False if this is the first pass through plugins, true otherwise. Slow plugins should run delayed.</param>
        /// <returns>A filtered list, can be empty when nothing was found</returns>
        public List<Result> Query(Query query, bool delayedExecution)
        {
            if (!delayedExecution || !_oneNoteInstalled || query is null || string.IsNullOrWhiteSpace(query.Search) || _cache is null)
            {
                return new List<Result>(0);
            }

            // Get results from cache if they already exist for this query, otherwise query OneNote. Results will be cached for 1 day.
            var results = _cache.GetOrAdd(query.Search, () =>
            {
                var pages = OneNoteProvider.FindPages(query.Search);

                return pages.Select(p => new Result
                {
                    IcoPath = _iconPath,
                    Title = p.Name,
                    QueryTextDisplay = p.Name,
                    SubTitle = @$"{p.Notebook.Name}\{p.Section.Name}",
                    Action = (_) => OpenPageInOneNote(p),
                    ContextData = p,
                    ToolTipData = new ToolTipData(Name, @$"{p.Notebook.Name}\{p.Section.Name}\{p.Name}"),
                }).ToList();
            });

            return results;
        }

        /// <summary>
        /// Return the translated plugin title.
        /// </summary>
        /// <returns>A translated plugin title.</returns>
        public string GetTranslatedPluginTitle() => Resources.PluginTitle;

        /// <summary>
        /// Return the translated plugin description.
        /// </summary>