public async Task OnGetAsync() { var sw = Stopwatch.StartNew(); //一瞬でも速くしたいので先にTaskを作って必要なところでawaitする var TargetUserTask = DB.SelectUser(UserId); Params = new TLUserParameters(); var ParamsTask = Params.InitValidate(HttpContext); if (Date.HasValue) { Before = SnowFlake.SecondinSnowFlake(DateTimeOffset.FromUnixTimeSeconds(Date.Value), true); } long LastTweet = Before ?? After ?? SnowFlake.Now(true); bool IsBefore = Before.HasValue || !After.HasValue; await ParamsTask.ConfigureAwait(false); //crawlinfoは「自分のツイート」のときだけ取得する var CrawlInfoTask = Params.ID == UserId?DB.SelectCrawlInfo(UserId) : null; var TweetsTask = DB.SimilarMediaUser(UserId, Params.ID, LastTweet, Params.TLUser_Count, 3, Params.TLUser_RT, Params.TLUser_Show0, IsBefore); await Task.WhenAll(TargetUserTask, TweetsTask).ConfigureAwait(false); if (CrawlInfoTask != null) { Crawlinfo = await CrawlInfoTask.ConfigureAwait(false); } TargetUser = TargetUserTask.Result; Tweets = TweetsTask.Result; if (Tweets.Length == 0) { HttpContext.Response.StatusCode = StatusCodes.Status404NotFound; } QueryElapsedMilliseconds = sw.ElapsedMilliseconds; }
public async Task <ActionResult> OnGetAsync() { var sw = Stopwatch.StartNew(); //一瞬でも速くしたいので先にTaskを作って必要なところでawaitする Params = new TLUserParameters(); var ParamsTask = Params.InitValidate(HttpContext); if (Date.HasValue) { Before = SnowFlake.SecondinSnowFlake(DateTimeOffset.FromUnixTimeSeconds(Date.Value), true); } long LastTweet = Before ?? After ?? SnowFlake.Now(true); bool IsBefore = Before.HasValue || !After.HasValue; await ParamsTask.ConfigureAwait(false); if (!Params.ID.HasValue) { return(LocalRedirect("/")); } var CrawlInfoTask = DB.SelectCrawlInfo(Params.ID.Value); var TargetUserTask = DB.SelectUser(Params.ID.Value); var TweetsTask = DB.SimilarMediaTimeline(Params.ID.Value, Params.ID, LastTweet, Params.TLUser_Count, 3, Params.TLUser_RT, Params.TLUser_Show0, IsBefore); await Task.WhenAll(TargetUserTask, TweetsTask, CrawlInfoTask).ConfigureAwait(false); TargetUser = TargetUserTask.Result; Tweets = TweetsTask.Result; Crawlinfo = CrawlInfoTask.Result; if (Tweets.Length == 0) { HttpContext.Response.StatusCode = StatusCodes.Status404NotFound; } QueryElapsedMilliseconds = sw.ElapsedMilliseconds; return(Page()); }