From d2db55237b16f925c9921d5b672f848e3bca5088 Mon Sep 17 00:00:00 2001 From: xxbiohazrdxx Date: Sun, 6 Aug 2023 16:51:18 -0400 Subject: [PATCH 1/3] Add indexing of Descriptions from metadata --- .../Partitions/PartitionRegistration.cs | 2 +- .../Storage/Index/DescriptionsIndex.cs | 33 +++++++++++++++++++ .../PackageGraph/Storage/Index/IndexTypes.cs | 2 ++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/microsoft-update-partition/PackageGraph/Storage/Index/DescriptionsIndex.cs diff --git a/src/microsoft-update-partition/PackageGraph/Partitions/PartitionRegistration.cs b/src/microsoft-update-partition/PackageGraph/Partitions/PartitionRegistration.cs index 0c4834f8..114fd51f 100644 --- a/src/microsoft-update-partition/PackageGraph/Partitions/PartitionRegistration.cs +++ b/src/microsoft-update-partition/PackageGraph/Partitions/PartitionRegistration.cs @@ -20,7 +20,7 @@ class PartitionRegistration { Factory = null, HasExternalContentFileMetadata = false, - Indexes = new List() { TitlesIndex.TitlesIndexDefinition }, + Indexes = new List() { TitlesIndex.TitlesIndexDefinition, DescriptionsIndex.DescriptionsIndexDefinition }, HandlesIdentities = false, } }, diff --git a/src/microsoft-update-partition/PackageGraph/Storage/Index/DescriptionsIndex.cs b/src/microsoft-update-partition/PackageGraph/Storage/Index/DescriptionsIndex.cs new file mode 100644 index 00000000..d1bd5e15 --- /dev/null +++ b/src/microsoft-update-partition/PackageGraph/Storage/Index/DescriptionsIndex.cs @@ -0,0 +1,33 @@ +using Microsoft.PackageGraph.ObjectModel; + +namespace Microsoft.PackageGraph.Storage.Index +{ + class DescriptionsIndex : SimpleIndex, ISimpleMetadataIndex + { + internal static readonly IndexDefinition DescriptionsIndexDefinition = + new() + { + Name = AvailableIndexes.DescriptionsIndexName, + PartitionName = null, + Version = DescriptionsIndex.CurrentVersion, + Factory = new InternalIndexFactory(), + Tag = "stream" + }; + + public override IndexDefinition Definition => DescriptionsIndexDefinition; + + public DescriptionsIndex(IIndexContainer container) : base(container, AvailableIndexes.TitlesIndexName) + { + } + + public override void IndexPackage(IPackage package, int packageIndex) + { + Add(packageIndex, package.Description); + } + + public new bool TryGet(int packageIndex, out string description) + { + return base.TryGet(packageIndex, out description); + } + } +} diff --git a/src/microsoft-update-partition/PackageGraph/Storage/Index/IndexTypes.cs b/src/microsoft-update-partition/PackageGraph/Storage/Index/IndexTypes.cs index e63ca78e..96fcbf45 100644 --- a/src/microsoft-update-partition/PackageGraph/Storage/Index/IndexTypes.cs +++ b/src/microsoft-update-partition/PackageGraph/Storage/Index/IndexTypes.cs @@ -8,6 +8,7 @@ namespace Microsoft.PackageGraph.Storage.Index abstract class AvailableIndexes { public const string TitlesIndexName = "titles"; + public const string DescriptionsIndexName = "descriptions"; } class InternalIndexFactory : IIndexFactory @@ -17,6 +18,7 @@ public IIndex CreateIndex(IndexDefinition definition, IIndexContainer container) return definition.Name switch { AvailableIndexes.TitlesIndexName => new TitlesIndex(container), + AvailableIndexes.DescriptionsIndexName => new DescriptionsIndex(container), _ => throw new NotImplementedException(), }; } From 68ad76084d77c505c2352b31b23cb7bb42e3a9da Mon Sep 17 00:00:00 2001 From: xxbiohazrdxx Date: Sun, 6 Aug 2023 22:49:20 -0400 Subject: [PATCH 2/3] Added index lookup logic to Description --- .../Metadata/UpdateBase.cs | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/microsoft-update-partition/Metadata/UpdateBase.cs b/src/microsoft-update-partition/Metadata/UpdateBase.cs index 23af3ae6..cb659788 100644 --- a/src/microsoft-update-partition/Metadata/UpdateBase.cs +++ b/src/microsoft-update-partition/Metadata/UpdateBase.cs @@ -164,18 +164,29 @@ public string Description { get { - if (_MetadataLoaded) + if (_DescriptionLoaded) { return _Description; } - else - { - LoadNonIndexedMetadataBase(); - return _Description; - } - } + else if (_FastLookupSource != null) + { + _FastLookupSource.TrySimpleKeyLookup(_Id, Storage.Index.AvailableIndexes.DescriptionsIndexName, out string description); + return description; + } + else if (_MetadataSource != null) + { + LoadNonIndexedMetadataBase(); + _DescriptionLoaded = true; + return _Description; + } + else + { + return null; + } + } } - private string _Description = null; + private bool _DescriptionLoaded; + private string _Description = null; /// /// Gets the list of files (content) for update From 14eeffeb9f323057f746ecc65523118deeaa0da8 Mon Sep 17 00:00:00 2001 From: xxbiohazrdxx Date: Sun, 6 Aug 2023 22:53:44 -0400 Subject: [PATCH 3/3] Set Description loaded in constructor --- src/microsoft-update-partition/Metadata/UpdateBase.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/microsoft-update-partition/Metadata/UpdateBase.cs b/src/microsoft-update-partition/Metadata/UpdateBase.cs index cb659788..5fad9b32 100644 --- a/src/microsoft-update-partition/Metadata/UpdateBase.cs +++ b/src/microsoft-update-partition/Metadata/UpdateBase.cs @@ -475,6 +475,7 @@ internal MicrosoftUpdatePackage(MicrosoftUpdatePackageIdentity id, XPathNavigato _TitleLoaded = true; _Description = UpdateParser.GetDescription(metadataNavigator, namespaceManager); + _DescriptionLoaded = true; _MetadataLoaded = true; _Prerequisites = PrerequisiteParser.FromXml(metadataNavigator, namespaceManager);