Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
chunks fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm360 committed Oct 20, 2024
1 parent 3930bda commit 3516cf9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
8 changes: 5 additions & 3 deletions src/BeeTurbo.Domain/Models/Chunk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// If not, see <https://www.gnu.org/licenses/>.

using Etherna.BeeNet.Models;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;

namespace Etherna.BeeTurbo.Domain.Models
{
Expand All @@ -23,14 +23,16 @@ public class Chunk : EntityModelBase<string>
public Chunk(SwarmHash hash, byte[] payload)
{
Hash = hash;
Payload = payload.AsReadOnly();
Payload = payload;
}
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
public Chunk() { }
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.

// Properties.
public virtual SwarmHash Hash { get; protected set; }
public virtual IReadOnlyCollection<byte> Payload { get; protected set; }

[SuppressMessage("Performance", "CA1819:Properties should not return arrays")]
public virtual byte[] Payload { get; protected set; }
}
}
16 changes: 7 additions & 9 deletions src/BeeTurbo.Persistence/BeehiveDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,19 @@ public class BeehiveDbContext : DbContext, IBeehiveDbContext
IndexBuilders =
[
(Builders<Chunk>.IndexKeys.Ascending(c => c.CreationDateTime), new CreateIndexOptions<Chunk>()),
(Builders<Chunk>.IndexKeys.Ascending(c => c.Hash), new CreateIndexOptions<Chunk> { Unique = true })
(Builders<Chunk>.IndexKeys.Ascending(c => c.Hash), new CreateIndexOptions<Chunk>())
]
});
public GridFSBucket ChunksBucket
{
get
{
if (_chunksBucket == null)
_chunksBucket = new GridFSBucket(Database, new GridFSBucketOptions
{
BucketName = "chunks",
WriteConcern = WriteConcern.WMajority,
ReadPreference = ReadPreference.Secondary
});
return _chunksBucket;
return _chunksBucket ??= new GridFSBucket(Database, new GridFSBucketOptions
{
BucketName = "chunks",
WriteConcern = WriteConcern.WMajority,
ReadPreference = ReadPreference.Secondary
});
}
}

Expand Down
8 changes: 7 additions & 1 deletion src/BeeTurbo.Persistence/ModelMaps/ChunkMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// If not, see <https://www.gnu.org/licenses/>.

using Etherna.BeeTurbo.Domain.Models;
using Etherna.MongoDB.Bson.Serialization.Serializers;
using Etherna.MongODM.Core;
using Etherna.MongODM.Core.Serialization;

Expand All @@ -23,7 +24,12 @@ internal sealed class ChunkMap : IModelMapsCollector
public void Register(IDbContext dbContext)
{
dbContext.MapRegistry.AddModelMap<Chunk>( //v0.2.4
"06aaf593-07af-4fca-99a9-bdc3718547d8");
"06aaf593-07af-4fca-99a9-bdc3718547d8",
mm =>
{
mm.AutoMap();
mm.MapProperty(c => c.Payload).SetSerializer(ByteArraySerializer.Instance);
});
}
}
}
8 changes: 7 additions & 1 deletion src/BeeTurbo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ private static void ConfigureLogging()

private static void ConfigureServices(WebApplicationBuilder builder, string beeUrl)
{
var services = builder.Services;
var config = builder.Configuration;
var services = builder.Services;

// Add services.
services.AddCors();
Expand Down Expand Up @@ -198,6 +198,12 @@ private static void ConfigureApplication(WebApplication app, string beeUrl)
handler.HandleAsync(httpContext));

app.MapForwarder("/{**catch-all}", beeUrl);

// Internal features mapping
app.Map("db/migrate", (IBeehiveDbContext dbContext) =>
{
dbContext.Chunks.BuildIndexesAsync();
});
}
}
}

0 comments on commit 3516cf9

Please sign in to comment.