Files
Abdullah Atta 960c4363b6 sync: keep pushed ciphers as UTF-8 from the hub to MongoDB (#118)
* sync: keep pushed ciphers as UTF-8 from the hub to MongoDB

Pushed ciphers were parsed into strings, then encoded back to UTF-8 by
the driver into a new buffer for each large one: the two largest
sources of large object heap allocations on prod.

PushItems now reads each cipher straight into a pooled UTF-8 buffer and
UpsertMany writes the item's BSON itself, from that buffer, into another
pooled one. The stored documents are unchanged. Validation moves to
SyncItemValidator, and the base64 check is vectorized.

* sync: hand back pushed buffers when a push is rejected

The hub disposed the pushed items only after its own checks, and the
authorization filter rejects a call after SignalR has bound it, so those
rejections left their pooled buffers to the GC. A push with null items
also made the cleanup throw over the real error.
2026-10-31 10:53:00 +05:00

30 lines
787 B
C#

using Notesnook.API.Models;
namespace Notesnook.API.Tests;
public static class TestItems
{
public static SyncItem Note(string itemId) => new()
{
ItemId = itemId,
Algorithm = Algorithms.Default,
Cipher = Convert.ToBase64String(new byte[16]),
IV = Convert.ToBase64String(new byte[24]),
Length = 16,
Version = 5.9
};
public static PushedSyncItem Pushed(SyncItem item) => new()
{
ItemId = item.ItemId,
Algorithm = item.Algorithm,
Cipher = PooledUtf8String.FromString(item.Cipher),
IV = item.IV,
Length = item.Length,
Version = item.Version,
KeyVersion = item.KeyVersion
};
public static PushedSyncItem PushedNote(string itemId) => Pushed(Note(itemId));
}