Skip to content

Commit

Permalink
index api compression attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-zhur committed Oct 1, 2024
1 parent 51823bd commit 58892c4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Text;
using System.Text.Json.Serialization;
using OneShelf.Common;

namespace HarmonyDB.Common.Representations.OneShelf;

Expand Down Expand Up @@ -177,4 +178,24 @@ internal override void AppendHtmlTo(StringBuilder builder, RepresentationSetting
{
return TraverseAll().Count();
}

public void Fix0_Compress()
{
foreach (var nodeCollectionBase in TraverseAll().Select(x => x.element).OfType<NodeCollectionBase>().ToList())
{
var newChildren = nodeCollectionBase.Children.ToChunks(x => x.NodeText != null)
.SelectMany(c =>
!c.criterium
? c.chunk
: new NodeText(string.Join(string.Empty, c.chunk.Select(x => x.NodeText!.Text))).AsChild()
.Once())
.ToList();

if (newChildren.Count != nodeCollectionBase.Children.Count)
{
nodeCollectionBase.Children.Clear();
nodeCollectionBase.Children.AddRange(newChildren);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ async Task<List<Chords>> Process(int sourceIndex, IReadOnlyCollection<string> ex
.Where(x => externalIds.Contains(x.Key) && x.Key == x.Value.ExternalId && sourceIndex == _downstreamApiClient.GetDownstreamSourceIndexBySourceKey(x.Value.Source))
.Select(x =>
{
x.Value.Output.Fix0_Compress();
x.Value.Source = _downstreamApiClient.GetSourceTitle(x.Value.Source);
return x.Value;
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public async Task<GetSongResponse> GetSong(string externalId)
var sourceIndex = _downstreamApiClient.GetDownstreamSourceIndexByExternalId(externalId);
var getSongResponse = await _downstreamApiClient.V1GetSong(sourceIndex, externalId);
getSongResponse.Song.Source = _downstreamApiClient.GetSourceTitle(getSongResponse.Song.Source);
getSongResponse.Song.Output.Fix0_Compress();
return getSongResponse;
}
}

0 comments on commit 58892c4

Please sign in to comment.