Skip to content

Commit

Permalink
Release 0.17.2. See release notes or expand full commit message for d…
Browse files Browse the repository at this point in the history
…etails.

[Fixes]
Fixed an issue where CachedNameApi was using the 'nocache' parameter to determine whether to use the cache layer, instead of simply delegating to the underlying API. 'nocache' has nothing to do with the caching layer, the parameter is only used by the Kubo API.
Removed unused syntax sugar GenericKuboExtensions.GetDagCidAsync. Call the Dag API instead.
  • Loading branch information
Arlodotexe committed Aug 23, 2024
1 parent c2d1b36 commit f072575
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 41 deletions.
25 changes: 1 addition & 24 deletions src/Cache/CachedNameApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,35 +166,12 @@ public async Task<NamedContent> PublishAsync(Cid id, string key = "self", TimeSp

/// <inheritdoc />
/// <remarks>
/// Using nocache = true here forces immediate name resolution via API, falling back to cache on failure.
/// <para/>
/// Using nocache = false here checks the cache first, and falls back to the API if not found.
/// nocache has nothing to do with this caching layer. The parameter is only used by Kubo.
/// </remarks>
public async Task<string> ResolveAsync(string name, bool recursive = false, bool nocache = false, CancellationToken cancel = default)
{
using (await _cacheUpdateMutex.DisposableWaitAsync(cancel))
{
if (nocache)
{
try
{
// Don't resolve with cache, but still save resolved data to cache.
var resToCache = await Inner.ResolveAsync(name, recursive, nocache, cancel);

var existing = ResolvedNames.FirstOrDefault(x => x.name == name);
if (existing is not null)
ResolvedNames.Remove(existing);

ResolvedNames.Add(new(name, recursive, resToCache));

return resToCache;
}
catch
{
// request failed, continue with cache anyway
}
}

// Check if name is in published cache
if (PublishedCidNamedContent.FirstOrDefault(x => x.returnValue.NamePath is not null && (name.Contains(x.returnValue.NamePath) || x.returnValue.NamePath.Contains(name))) is { } publishedCidNamedContent)
{
Expand Down
25 changes: 9 additions & 16 deletions src/Extensions/GenericKuboExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,6 @@ namespace OwlCore.Kubo;
/// </summary>
public static partial class GenericKuboExtensions
{
/// <summary>
/// Gets the CID of the provided <paramref name="serializable"/> object.
/// </summary>
/// <param name="serializable">The object to serialize into the Dag.</param>
/// <param name="client">A client that can be used to communicate with Ipfs.</param>
/// <param name="pin">Whether to pin the provided data to the node, keeping it retrievable until unpinned. Defaults to false.</param>
/// <param name="cancellationToken">A token that can be used to cancel the ongoing operation.</param>
/// <returns></returns>
public static Task<Cid> GetDagCidAsync(this object serializable, ICoreApi client, bool pin = false, CancellationToken cancellationToken = default)
{
return client.Dag.PutAsync(serializable, cancel: cancellationToken, pin: pin);
}

/// <summary>
/// Resolves the provided <paramref name="cid"/> if it is an Ipns address and retrieves the content from the DAG.
/// </summary>
Expand Down Expand Up @@ -144,7 +131,7 @@ public static async Task<IKey> GetOrCreateKeyAsync(this IKeyApi keyApi, string k
/// <param name="cancellationToken">A token that can be used to cancel the ongoing task.</param>
/// <param name="getDefaultValue">Given the created ipns key, provides the default value to be published to it.</param>
/// <returns></returns>
public static async Task<IKey> GetOrCreateKeyAsync<TResult>(this ICoreApi client, string keyName, Func<IKey, TResult> getDefaultValue, TimeSpan ipnsLifetime, int size = 4096, CancellationToken cancellationToken = default)
public static async Task<(IKey Key, TResult Value)> GetOrCreateKeyAsync<TResult>(this ICoreApi client, string keyName, Func<IKey, TResult> getDefaultValue, TimeSpan ipnsLifetime, bool nocache, int size = 4096, CancellationToken cancellationToken = default)
{
// Get or create ipns key
var keys = await client.Key.ListAsync(cancellationToken);
Expand All @@ -161,8 +148,14 @@ public static async Task<IKey> GetOrCreateKeyAsync<TResult>(this ICoreApi client
// Publish default value cid
var cid = await client.Dag.PutAsync(defaultValue, cancel: cancellationToken, pin: true);
await client.Name.PublishAsync(cid, key.Name, ipnsLifetime, cancellationToken);
}

return key;
return (key, defaultValue);
}
else
{
var (existingValue, _) = await key.Id.ResolveDagCidAsync<TResult>(client, nocache, cancellationToken);
Guard.IsNotNull(existingValue);
return (key, existingValue);
}
}
}
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.17.1</Version>
<Version>0.17.2</Version>
<Product>OwlCore</Product>
<Description>
An essential toolkit for Kubo, IPFS and the distributed web.
</Description>
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
<PackageReleaseNotes>
--- 0.17.2 ---
[Fixes]
Fixed an issue where CachedNameApi was using the 'nocache' parameter to determine whether to use the cache layer, instead of simply delegating to the underlying API. 'nocache' has nothing to do with the caching layer, the parameter is only used by the Kubo API.
Removed unused syntax sugar GenericKuboExtensions.GetDagCidAsync. Call the Dag API instead.

--- 0.17.1 ---
[Improvements]
Bumped OwlCore to 0.6.0.
Expand Down

0 comments on commit f072575

Please sign in to comment.