Skip to content

Commit

Permalink
rename lite.Retrieve() to lite.RetrieveAndRemember()
Browse files Browse the repository at this point in the history
  • Loading branch information
olmobrutall committed Jul 16, 2019
1 parent 9dfe0be commit b3b1189
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Signum.Engine/Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public static int InsertView<T>(this T viewObject) where T : IView



public static T Retrieve<T>(this Lite<T> lite) where T : class, IEntity
public static T RetrieveAndRemember<T>(this Lite<T> lite) where T : class, IEntity
{
if (lite == null)
throw new ArgumentNullException(nameof(lite));
Expand All @@ -99,7 +99,7 @@ public static T Retrieve<T>(this Lite<T> lite) where T : class, IEntity
return lite.EntityOrNull!;
}

public static async Task<T> RetrieveAsyc<T>(this Lite<T> lite, CancellationToken token) where T : class, IEntity
public static async Task<T> RetrieveAndRememberAsyc<T>(this Lite<T> lite, CancellationToken token) where T : class, IEntity
{
if (lite == null)
throw new ArgumentNullException(nameof(lite));
Expand Down
4 changes: 2 additions & 2 deletions Signum.Test/Environment/MusicLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public static void Register()
ToStates = { AlbumState.New },
Construct = (albumLites, _) =>
{
List<AlbumEntity> albums = albumLites.Select(a => a.Retrieve()).ToList();
List<AlbumEntity> albums = albumLites.Select(a => a.RetrieveAndRemember()).ToList();
if (albums.Select(a => a.Author).Distinct().Count() > 1)
throw new ArgumentException("All album authors must be the same in order to create a Greatest Hits Album");
Expand All @@ -289,7 +289,7 @@ public static void Register()
ToStates = { AlbumState.New },
Construct = (albumLites, _) =>
{
List<AlbumEntity> albums = albumLites.Select(a => a.Retrieve()).ToList();
List<AlbumEntity> albums = albumLites.Select(a => a.RetrieveAndRemember()).ToList();
if (albums.Select(a => a.Author).Distinct().Count() > 1)
throw new ArgumentException("All album authors must be the same in order to create a Greatest Hits Album");
Expand Down
2 changes: 1 addition & 1 deletion Signum.Test/LinqProvider/RetriverTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void RetrieveWithMListCount()
{
var artist = Database.Query<ArtistEntity>().OrderBy(a => a.Name).First();

Assert.Equal(artist.ToLite().Retrieve().Friends.Count, artist.Friends.Count);
Assert.Equal(artist.ToLite().RetrieveAndRemember().Friends.Count, artist.Friends.Count);
}
}
}
2 changes: 1 addition & 1 deletion Signum.Test/LinqProvider/SelectTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ public void SelectView()
[Fact]
public void SelectRetrieve()
{
var e = Assert.Throws<InvalidOperationException>(() => Database.Query<LabelEntity>().Select(l => l.Owner!.Retrieve()).ToList());
var e = Assert.Throws<InvalidOperationException>(() => Database.Query<LabelEntity>().Select(l => l.Owner!.RetrieveAndRemember()).ToList());
Assert.Contains("not supported", e.Message);
}

Expand Down
6 changes: 3 additions & 3 deletions Signum.Test/SaveTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public void SmartSaveMList()
album.Save();

{
var album2 = album.ToLite().Retrieve();
var album2 = album.ToLite().RetrieveAndRemember();

Assert.True(album.Songs.Count == album2.Songs.Count);
Assert.True(innerList[0].RowId == ((IMListPrivate<SongEmbedded>)album2.Songs).InnerList[0].RowId);
Expand All @@ -185,7 +185,7 @@ public void SmartSaveMList()
album.Save();

{
var album2 = album.ToLite().Retrieve();
var album2 = album.ToLite().RetrieveAndRemember();

Assert.True(album.Songs.Count == album2.Songs.Count);
Assert.True(innerList[0].RowId == ((IMListPrivate<SongEmbedded>)album2.Songs).InnerList[0].RowId);
Expand Down Expand Up @@ -249,7 +249,7 @@ public void SmartSaveMListOrder()
AssertSequenceEquals(album.MListElements(a => a.Songs).OrderBy(a => a.Order).Select(mle => KVP.Create(mle.Order, mle.Element.Name)),
new Dictionary<int, string> { { 0, "Song 1" }, { 1, "Song 2" }, { 2, "Song 0" } });

AssertSequenceEquals(album.ToLite().Retrieve().Songs.Select(a => a.Name), new[] { "Song 1", "Song 2", "Song 0" });
AssertSequenceEquals(album.ToLite().RetrieveAndRemember().Songs.Select(a => a.Name), new[] { "Song 1", "Song 2", "Song 0" });

//tr.Commit();
}
Expand Down

1 comment on commit b3b1189

@olmobrutall
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lite.Retrieve renamed to lite.RetrieveAndRemember

Retrieve as extension method for Lite<T> has typically used or set the internal Entity field as cache to improve performance. Unfortunately, this optimization has sometimes unintended consequences on serialization and cache invalidation, so it was a bad idea. 😢

In React there is since the beginning fetchAndRemember and fetchAndForget, so it's about time to do the same in C#. Now RetrieveAndRemember uses the cache (old Retrieve behaviour), while RetrieveAndForget (untouched) does a database access every time and doesn't modify the Entity field.

How to update

FIND: (\w*)\.Retrieve\(\)
REPL: $1.RetrieveAndRemember()

Please sign in to comment.