Skip to content

Commit

Permalink
Release 0.16.5. Fixes and cleanup in CachedNameApi.
Browse files Browse the repository at this point in the history
[Fixes]
Fixed serialization issues with CachedNameApi.
Fixed multi-publishing in CachedNameApi when flushing after using both Path and Cid overloads.
  • Loading branch information
Arlodotexe committed Jul 18, 2024
1 parent 040a606 commit 033ff6b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
23 changes: 13 additions & 10 deletions src/Cache/CachedNameApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Ipfs;
using Ipfs.CoreApi;
using OwlCore.ComponentModel;
using OwlCore.Diagnostics;
using OwlCore.Extensions;
using OwlCore.Storage;

Expand All @@ -25,7 +26,7 @@ public record PublishedPathName(string path, bool resolve, string key, TimeSpan?
/// <summary>
/// The cached record for a published cid name in a <see cref="CachedNameApi"/>.
/// </summary>
public record PublishedCidName(Cid id, string key, TimeSpan? lifetime, NamedContent returnValue);
public record PublishedCidName(string cid, string key, TimeSpan? lifetime, NamedContent returnValue);

/// <summary>
/// The cached record for a resolved name in a <see cref="CachedNameApi"/>.
Expand Down Expand Up @@ -89,10 +90,8 @@ public async Task FlushAsync(CancellationToken cancellationToken = default)
{
cancellationToken.ThrowIfCancellationRequested();

Console.WriteLine($"Flushing key {item.key} with value {item.id}");

// Publish to ipfs
var result = await Inner.PublishAsync(item.id, item.key, item.lifetime, cancellationToken);
var result = await Inner.PublishAsync(item.cid, item.key, item.lifetime, cancellationToken);

// Verify result matches original returned data
_ = Guard.Equals(result.ContentPath, item.returnValue.ContentPath);
Expand All @@ -107,8 +106,6 @@ public async Task FlushAsync(CancellationToken cancellationToken = default)
{
cancellationToken.ThrowIfCancellationRequested();

Console.WriteLine($"Flushing key {item.key} with value {item.path}");

// Publish to ipfs
var result = await Inner.PublishAsync(item.path, item.resolve, item.key, item.lifetime, cancellationToken);

Expand All @@ -128,8 +125,11 @@ public async Task<NamedContent> PublishAsync(string path, bool resolve = true, s
{
using (await _cacheUpdateMutex.DisposableWaitAsync(cancel))
{
if (PublishedStringNamedContent.FirstOrDefault(x => x.key == key) is { } existing)
PublishedStringNamedContent.Remove(existing);
if (PublishedCidNamedContent.FirstOrDefault(x => x.key == key) is { } existingCidNamedContent)
PublishedCidNamedContent.Remove(existingCidNamedContent);

if (PublishedStringNamedContent.FirstOrDefault(x => x.key == key) is { } existingStringNameContent)
PublishedStringNamedContent.Remove(existingStringNameContent);

var keys = await KeyApi.ListAsync(cancel);
var existingKey = keys.FirstOrDefault(x => x.Name == key);
Expand All @@ -147,8 +147,11 @@ public async Task<NamedContent> PublishAsync(Cid id, string key = "self", TimeSp
{
using (await _cacheUpdateMutex.DisposableWaitAsync(cancel))
{
if (PublishedCidNamedContent.FirstOrDefault(x => x.key == key) is { } existing)
PublishedCidNamedContent.Remove(existing);
if (PublishedCidNamedContent.FirstOrDefault(x => x.key == key) is { } existingCidNamedContent)
PublishedCidNamedContent.Remove(existingCidNamedContent);

if (PublishedStringNamedContent.FirstOrDefault(x => x.key == key) is { } existingStringNameContent)
PublishedStringNamedContent.Remove(existingStringNameContent);

var keys = await KeyApi.ListAsync(cancel);
var existingKey = keys.FirstOrDefault(x => x.Name == key);
Expand Down
3 changes: 3 additions & 0 deletions src/Cache/KuboCacheSerializerContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ namespace OwlCore.Kubo.Cache;
[JsonSerializable(typeof(int))]
[JsonSerializable(typeof(List<string>))]
[JsonSerializable(typeof(List<CachedKeyApi.CachedKeyInfo>))]
[JsonSerializable(typeof(List<CachedNameApi.PublishedCidName>))]
[JsonSerializable(typeof(List<CachedNameApi.PublishedPathName>))]
[JsonSerializable(typeof(List<CachedNameApi.ResolvedName>))]
public partial class KuboCacheSerializerContext : JsonSerializerContext
{
}
7 changes: 6 additions & 1 deletion src/OwlCore.Kubo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>

<Author>Arlo Godfrey</Author>
<Version>0.16.4</Version>
<Version>0.16.5</Version>
<Product>OwlCore</Product>
<Description>
An essential toolkit for Kubo, IPFS and the distributed web.
</Description>
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
<PackageReleaseNotes>
--- 0.16.5 ---
[Fixes]
Fixed serialization issues with CachedNameApi.
Fixed multi-publishing in CachedNameApi when flushing after using both Path and Cid overloads.

--- 0.16.4 ---
[Fixes]
Fixed decryption on AesPasswordEncryptedPubSub, addressed usage of deprecated Rfc2898DeriveBytes constructor.
Expand Down

0 comments on commit 033ff6b

Please sign in to comment.