aboutsummaryrefslogtreecommitdiff
path: root/Timeline/Services
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2019-12-10 22:19:37 +0800
committercrupest <crupest@outlook.com>2019-12-10 22:19:37 +0800
commitf19dc927d773a86e9385c38d07a6e239f4f6c5fa (patch)
tree13dcdf360e18dd0719f76c3742c9467a1f51dcad /Timeline/Services
parent4210aaaa1cf4966ee2d1dc6e6fcf6bd9889e4159 (diff)
downloadtimeline-f19dc927d773a86e9385c38d07a6e239f4f6c5fa.tar.gz
timeline-f19dc927d773a86e9385c38d07a6e239f4f6c5fa.tar.bz2
timeline-f19dc927d773a86e9385c38d07a6e239f4f6c5fa.zip
Fix a bug in simultaneous database queries.
Note on this: You should not use Task.WhenAll to do a bunch of async database queries since EntityFramework Core does not support DbContext to do two queries in the same time.
Diffstat (limited to 'Timeline/Services')
-rw-r--r--Timeline/Services/TimelineService.cs16
1 files changed, 10 insertions, 6 deletions
diff --git a/Timeline/Services/TimelineService.cs b/Timeline/Services/TimelineService.cs
index affcff2e..af4537af 100644
--- a/Timeline/Services/TimelineService.cs
+++ b/Timeline/Services/TimelineService.cs
@@ -349,13 +349,17 @@ namespace Timeline.Services
var timelineId = await FindTimelineId(name);
var postEntities = await Database.TimelinePosts.OrderBy(p => p.Time).Where(p => p.TimelineId == timelineId && p.Content != null).ToListAsync();
- var posts = new List<TimelinePostInfo>(await Task.WhenAll(postEntities.Select(async p => new TimelinePostInfo
+ var posts = new List<TimelinePostInfo>();
+ foreach (var entity in postEntities)
{
- Id = p.Id,
- Content = p.Content,
- Author = (await Database.Users.Where(u => u.Id == p.AuthorId).Select(u => new { u.Name }).SingleAsync()).Name,
- Time = p.Time
- })));
+ posts.Add(new TimelinePostInfo
+ {
+ Id = entity.Id,
+ Content = entity.Content,
+ Author = (await Database.Users.Where(u => u.Id == entity.AuthorId).Select(u => new { u.Name }).SingleAsync()).Name,
+ Time = entity.Time
+ });
+ }
return posts;
}