PDA

View Full Version : بهترین روش بارگذاری صفحات با اطلاعات زیاد



mo7300
سه شنبه 08 خرداد 1397, 14:57 عصر
سلام
در یک سایت فروشگاهی برای بارگذاری مشخصات محصول،نظرات کاربران، پرسش و پاسخ بهترین روش چه روشی است
کد زیر داخل یکی از نمونه کدها بود اما به نظرم روش بهینه ایی نیست
این ویو مدل
public class VmProductDetails
{
public int ID { get; set; }
public string TitleFa { get; set; }
public string TitleEn { get; set; }
public int Star { get; set; }
public string RatingAvg { get; set; }
public string GuaruntyName { get; set; }
public string Author { get; set; }
public string Evaluation { get; set; }
public string StatusTitle { get; set; }
public string StatusImgUrl { get; set; }
public string Text { get; set; }
public bool Favo { get; set; }
public bool Noti { get; set; }
public string Price { get; set; }
public string SavePrice { get; set; }

public List<OtherProduct> OtherProduct { get; set; }
public List<Comment> listComment { get; set; }
public List<ProductProperty> ListProperty { get; set; }
public List<Asks> ListAsks { get; set; }
public List<ProductImage> ProductImg { get; set; }
public List<TechnicalPropety> TechnicalPropety { get; set; }
}

public class ProductProperty
{
/// <summary>
/// شناسه ارتباط محصول و مشخصه
/// </summary>
public int ID { get; set; }
public string PropName { get; set; }
public string Pice { get; set; }
}

public class ProductImage
{
public string ImageUrl { get; set; }
}

public class TechnicalPropety
{
public string Title { get; set; }
public string Value { get; set; }
}

public class OtherProduct
{
public string ImageUrl { get; set; }
public string Title { get; set; }
public string Price { get; set; }
}

public class Comment
{
public int ID { get; set; }
public string Name { get; set; }
public string Date { get; set; }
public string Title { get; set; }
public string Text { get; set; }
public int Like { get; set; }
public int DisLike { get; set; }
public int Item1 { get; set; }
public int Item2 { get; set; }
public int Item3 { get; set; }
public int Item4 { get; set; }
public int Item5 { get; set; }
public int Item6 { get; set; }
public string Bad { get; set; }
public string Best { get; set; }
}

public class Asks
{
public int ID { get; set; }
public int AskID { get; set; }
public string Name { get; set; }
public string Date { get; set; }
public int Like { get; set; }
public int DisLike { get; set; }
public string Text { get; set; }
}

این repository
public TblProducts ProductDetails(string TitleEn)
{
try
{
var qProduct = db.TblProducts
.Where(a => a.TitleEn == TitleEn)
//.Where(a => a.Disable == false)
.Include(a => a.TblFavos)
.Include(a => a.TblNoti)
.Include(a => a.TblTechnicalProp_Products).ThenInclude(a => a.TblTechnicalProp)
.Include(a => a.TblImages).ThenInclude(a => a.TblServer)
.Include(a => a.TblPropertis_Product).ThenInclude(a => a.TblPropertis)
.Include(a => a.TblComments).ThenInclude(a => a.TblUsers)
.Include(a => a.TblAsks).ThenInclude(a => a.TblUser)
.Include(a => a.TblRaiting)
.Include(a => a.TblGurunty)
.Include(a => a.TblUser)
.Include(a => a.TblPrices)
.Include(a => a.TblSpical)
.Include(a => a.TblCategory)
.SingleOrDefault();

return qProduct;

}
catch (Exception e)
{

}
}

این هم داخل کنترلر که البته کامل نشده
public IActionResult Product(string TitleEn)
{
ProductRepository RepProduct = new ProductRepository();
var q = RepProduct.ProductDetails(TitleEn);
VmProductDetails vmp = new VmProductDetails();

vmp.Author = q.TblUser.Name;
vmp.Evaluation = q.Evaluation;
vmp.Favo=User.Identity.IsAuthenticated?
(q.TblFavos.Where(a=>a.UserID==User.GetUserID()).SingleOrDefault()!=nul l?true:false):false;
vmp.GuaruntyName = q.TblGurunty.Title;
vmp.ID = q.ID;
vmp.Noti = User.Identity.IsAuthenticated ?
(q.TblNoti.Where(a => a.UserID == User.GetUserID()).SingleOrDefault() != null ? true : false) : false;
vmp.Price = q.TblPrices.OrderByDescending(a => a.ID).FirstOrDefault().Price;
vmp.RatingAvg = (q.TblRaiting.Sum(a => a.Star) / q.TblRaiting.Count()).ToString();

vmp.ListAsks = new List<Asks>();
foreach (var item in q.TblAsks)
{
Asks ask = new Asks();
ask.ID = item.ID;
ask.Like = item.Like;
ask.DisLike = item.DisLike;
ask.Name = item.TblUser.Name;
ask.Text = item.Text;
ask.AskID = item.AskID;
ask.Date = new TimeUtility().GetTime(item.Date);
vmp.ListAsks.Add(ask);
}

return View();
}

mo7300
پنج شنبه 10 خرداد 1397, 16:40 عصر
کسی نمیتونه راهنمایی کنه

ali_md110
پنج شنبه 10 خرداد 1397, 18:21 عصر
بهتره از ابزارهایی مثل AutoMapper برای Projection استفاده کنید جون کوئری شما رو مدیریت و include های اضافی ها رو حذف میکنه
و با ابزارهای پروفایلر هم چک کنید کوئری شما چقدر هزینه بر هست
بازگشت اکشن هاتون بصورت json مد نظر داشته باشید
میتونید کوئری Comment هاتون جدا گانه بزنید و بصورت یک پارشل ویو اجراش کنید