Skip to content

Commit

Permalink
Change behaviour of scrobbler to clear sent scrobbles when successful…
Browse files Browse the repository at this point in the history
… --- TODO handle batching
  • Loading branch information
rikkit committed Aug 23, 2017
1 parent 2e5619e commit 89ce093
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/IF.Lastfm.Core.Tests/Scrobblers/ScrobblerTestsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ public async Task ScrobblesExistingCachedTracks()
var scrobbleResponse2 = await ExecuteTestInternal(scrobblesToSend, responseMessage2, requestMessage2);

Assert.IsTrue(scrobbleResponse2.Success);

var remainingCount = await Scrobbler.GetCachedCountAsync();
Assert.AreEqual(0, remainingCount);
}

[Test]
Expand Down
9 changes: 9 additions & 0 deletions src/IF.Lastfm.Core/Scrobblers/Scrobbler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ public override Task<IEnumerable<Scrobble>> GetCachedAsync()
return Task.FromResult(Enumerable.Empty<Scrobble>());
}

public override async Task ClearCacheAsync()
{
}

public override Task<int> GetCachedCountAsync()
{
return Task.FromResult(0);
}

protected override Task<LastResponseStatus> CacheAsync(IEnumerable<Scrobble> scrobble, LastResponseStatus originalResponseStatus)
{
return Task.FromResult(originalResponseStatus);
Expand Down
6 changes: 6 additions & 0 deletions src/IF.Lastfm.Core/Scrobblers/ScrobblerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public async Task<ScrobbleResponse> ScrobbleAsyncInternal(IEnumerable<Scrobble>
if (!responses.Any() || responses.All(r => r.Success))
{
scrobblerResponse = new ScrobbleResponse(LastResponseStatus.Successful);

await ClearCacheAsync();
}
else
{
Expand Down Expand Up @@ -110,6 +112,10 @@ public async Task<ScrobbleResponse> ScrobbleAsyncInternal(IEnumerable<Scrobble>

public abstract Task<IEnumerable<Scrobble>> GetCachedAsync();

public abstract Task ClearCacheAsync();

public abstract Task<int> GetCachedCountAsync();

protected abstract Task<LastResponseStatus> CacheAsync(IEnumerable<Scrobble> scrobble, LastResponseStatus originalResponseStatus);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class SQLiteScrobblerTests : ScrobblerTestsBase

public override void Initialise()
{
var dbPath = Path.GetFullPath("test.db");
var dbPath = Path.GetFullPath($"test-{DateTime.UtcNow.ToFileTimeUtc()}.sqlite");
File.Delete(dbPath);
using (File.Create(dbPath))
{
Expand All @@ -25,9 +25,9 @@ public override void Initialise()

public override void Cleanup()
{
GC.Collect();
GC.WaitForPendingFinalizers();
File.Delete(_dbPath);
//GC.Collect();
//GC.WaitForPendingFinalizers();
//File.Delete(_dbPath);

base.Cleanup();
}
Expand Down

0 comments on commit 89ce093

Please sign in to comment.