У меня угловой проект 6. И у меня есть форма с 20 combobox и текстовым полем, как на картинке ниже. Итак, я связываю элементы списка при загрузке страницы. Есть два подхода для этого, как показано ниже.
ИЗОБРАЖЕНИЕ В МОЕЙ ФОРМЕ
ПЕРВЫЙ ПОДХОД:
.ts file
onInit(){
let countries= this.http.get("getCountries");
let cities= this.http.get("getCities");
let states= this.http.get("getStates");
let universities= this.http.get("getUniversities");
let elementarySchools= this.http.get("getElementarySchools");
let studentTypes= this.http.get("getStudentTypes");
let universityTypes= this.http.get("getUniversityTypes");
let genders= this.http.get("getGenders");
let diseaseTypes= this.http.get("getDiseaseTypes");
let accessTypes= this.http.get("getAccessTypes");
let appealTypes= this.http.get("getAppealTypes");
let computerBrands= this.http.get("getComputerBrands");
let carTypes= this.http.get("getCarTypes");
let positions= this.http.get("getPositions");
let workingTypes= this.http.get("getWorkingTypes");
let travelTypes= this.http.get("getTravelTypes");
let feedbacks= this.http.get("getFeedbacks");
let contactTypes= this.http.get("getContactTypes");
let maritalStatus= this.http.get("getMaritalStatus");
}
ApiController.cs
public List<string> getCountries()
{ return new List<string>{"sgh","shd","dfh"}; }
public List<string> getCities()
{ return new List<string>{"agg","dfh","dfj"}; }
public List<string> getStates()
{ return new List<string>{"ghf","ghj","jhk"}; }
public List<string> getUniversities()
{ return new List<string>{"sdh","dfj","hgj"}; }
public List<string> getElementarySchools()
{ return new List<string>{"jhg","fdh","fsg"}; }
public List<string> getStudentTypes()
{ return new List<string>{"asf","sdf","fdh"}; }
public List<string> getUniversityTypes()
{ return new List<string>{"fdh","asd","tyr"}; }
public List<string> getGenders()
{ return new List<string>{"ewt","ret","uer"}; }
public List<string> getDiseaseTypes()
{ return new List<string>{"asd","zxc","vbn"}; }
public List<string> getAccessTypes()
{ return new List<string>{"wet","wtt","yrx"}; }
public List<string> getAppealTypes()
{ return new List<string>{"asd","zxc","vbn"}; }
public List<string> getComputerBrands()
{ return new List<string>{"asd","zxc","dfh"}; }
public List<string> getCarTypes()
{ return new List<string>{"asd","zxc","sdf"}; }
public List<string> getPositions()
{ return new List<string>{"asd","zxc","bfg"}; }
public List<string> getWorkingTypes()
{ return new List<string>{"dfh","zxc","dhj"}; }
public List<string> getTravelTypes()
{ return new List<string>{"hgj","zxc","jfd"}; }
public List<string> getFeedbacks()
{ return new List<string>{"khg","zxc","vbn"}; }
public List<string> getContactTypes()
{ return new List<string>{"cvn","zxc","gsh"}; }
public List<string> getMaritalStatus()
{ return new List<string>{"dfh","zxc","vbn"}; }
ВТОРОЙ ПОДХОД:
.ts file
onInit(){
this.http.get("getAllComboboxBindingLists");
}
ApiController.cs
public List<List<string>> getAllComboboxBindingLists()
{
var resultList = new List<List<string>>();
resultList.Add(new List<string>{"sgh","shd","dfh"});
resultList.Add(new List<string>{"dfg","fgh","dhh"});
resultList.Add(new List<string>{"hjf","gfh","sdf"});
resultList.Add(new List<string>{"sjf","ghj","dfj"});
resultList.Add(new List<string>{"agg","fdg","fgj"});
resultList.Add(new List<string>{"nfd","ghj","fdg"});
resultList.Add(new List<string>{"ghj","dfh","dfj"});
resultList.Add(new List<string>{"ghk","hjk","ghj"});
resultList.Add(new List<string>{"agg","yuı","gfh"});
resultList.Add(new List<string>{"ret","yuı","yuı"});
resultList.Add(new List<string>{"ghj","dfh","dfj"});
resultList.Add(new List<string>{"fjj","gfh","tyu"});
resultList.Add(new List<string>{"set","dfg","dfj"});
resultList.Add(new List<string>{"yru","tuı","try"});
resultList.Add(new List<string>{"tru","dfh","hjg"});
resultList.Add(new List<string>{"agg","wry","dfj"});
resultList.Add(new List<string>{"ghj","hjk","dfj"});
resultList.Add(new List<string>{"dfg","fgj","dfj"});
resultList.Add(new List<string>{"yjg","yır","rjf"});
resultList.Add(new List<string>{"rwy","tru","ıtu"});
return resultList;
}
Преимущества и недостатки первого подхода
- Преимущество: Мы можем использовать методы на других страницах. Потому что у каждого метода есть свой метод. Например, вы можете вызывать «getUniversityTypes» отовсюду.
- Недостаток: Отправляем 20 запросов на сервер
Преимущества и недостатки второго подхода
- Преимущество: Мы отправляем только один запрос на сервер
- Недостаток: Мы не можем использовать методы с других страниц. Потому что в controller.cs есть только один метод и получение всех значений. Таким образом, вы не можете привести пример только "getUniversityTypes"
Мой вопрос
Есть ли разница в производительности этих двух подходов и сколько? Потому что мое приложение будет использовать миллионов человек , и таких страниц будет сотни. И эта разница в производительности очень важна для меня. (Думаю, при первом подходе серверу надоедает из-за запроса 20 раз)