Is it possible to get rid of code repetition and speed up its execution? [closed]Refactoring a loop through...
How does the math work for Perception checks?
Multiplicative persistence
Travelling outside the UK without a passport
New brakes for 90s road bike
Is there any references on the tensor product of presentable (1-)categories?
Is it better practice to read straight from sheet music rather than memorize it?
How to implement a feedback to keep the DC gain at zero for this conceptual passive filter?
What changes for testers when they are testing in agile environments?
Is there a RAID 0 Equivalent for RAM?
Are the IPv6 address space and IPv4 address space completely disjoint?
How much character growth crosses the line into breaking the character
A social experiment. What is the worst that can happen?
Temporarily disable WLAN internet access for children, but allow it for adults
Yosemite Fire Rings - What to Expect?
Rising and falling intonation
What is this called? Old film camera viewer?
Why should universal income be universal?
How to create ADT in Haskell?
Redundant comparison & "if" before assignment
Did arcade monitors have same pixel aspect ratio as TV sets?
Is (0,1] a closed or open set?
Has any country ever had 2 former presidents in jail simultaneously?
Pre-mixing cryogenic fuels and using only one fuel tank
If infinitesimal transformations commute why dont the generators of the Lorentz group commute?
Is it possible to get rid of code repetition and speed up its execution? [closed]
Refactoring a loop through repetitive registersConverting from binary to unaryA non-static Sieve of Eratosthenes class, version 1Automated collage toolLeetcode 317: Shortest distance from all buildingsTask Wrappers for starting operation only if previous task has finishedMapper made specifically to work with DapperLINQ-ifying Colour Generation from StringsAdjusting business logic conveniently through JSON and expression treesIterating over combinations
$begingroup$
I do not like the repetition of the code and the use of slow LINQ. Cannot change search methods. It is necessary to optimize the code in this context. Thanks for any help.
public static IEnumerable<ElasticVideoMaterial> FilerResults(FilterData data)
{
List<ElasticVideoMaterial> result = new List<ElasticVideoMaterial>();
if (data.Countries != null && data.Countries.Any())
{
string countries = string.Join(",", data.Countries);
var resultByCountries = MotusElasticsearch.SearchByCountrieName(countries);
if(resultByCountries.Any())
{
result.AddRange(resultByCountries);
}
}
if (data.Genres != null && data.Genres.Any())
{
string genres = string.Join(",", data.Genres);
var resultByGenres = MotusElasticsearch.SearchByGenreTitle(genres);
if (result.Any() && resultByGenres.Any())
{
result.Intersect(resultByGenres);
}
else if (resultByGenres.Any())
{
result.AddRange(resultByGenres);
}
}
if (data.Translations != null && data.Translations.Any())
{
string translations = string.Join(",", data.Translations);
var resultByTranslations = MotusElasticsearch.SearchByTranslationTitle(translations);
if (result.Any() && resultByTranslations.Any())
{
result.Intersect(resultByTranslations);
}
else if (resultByTranslations.Any())
{
result.AddRange(resultByTranslations);
}
}
if (data.MinImdb != 0)
{
var resultByImdb = MotusElasticsearch.SearchByIMDB(data.MinImdb);
if (result.Any() && resultByImdb.Any())
{
result.Intersect(resultByImdb);
}
else if (resultByImdb.Any())
{
result.AddRange(resultByImdb);
}
}
if (data.MinKinopoisk != 0)
{
var resultByKinopoisk = MotusElasticsearch.SearchByKinopoiskRating(data.MinKinopoisk);
if (result.Any() && resultByKinopoisk.Any())
{
result.Intersect(resultByKinopoisk);
}
else if (resultByKinopoisk.Any())
{
result.AddRange(resultByKinopoisk);
}
}
if (data.MaxReliseDateValue != 0)
{
var resultByReliseDate = MotusElasticsearch.SearchByReliseDate(data.MinReliseDateValue,data.MaxReliseDateValue);
if (result.Any() && resultByReliseDate.Any())
{
result.Intersect(resultByReliseDate);
}
else if (resultByReliseDate.Any())
{
result.AddRange(resultByReliseDate);
}
}
return result;
}
c# .net
$endgroup$
closed as off-topic by πάντα ῥεῖ, t3chb0t, Jamal♦ Mar 16 at 2:26
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – πάντα ῥεῖ, t3chb0t, Jamal
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
$begingroup$
I do not like the repetition of the code and the use of slow LINQ. Cannot change search methods. It is necessary to optimize the code in this context. Thanks for any help.
public static IEnumerable<ElasticVideoMaterial> FilerResults(FilterData data)
{
List<ElasticVideoMaterial> result = new List<ElasticVideoMaterial>();
if (data.Countries != null && data.Countries.Any())
{
string countries = string.Join(",", data.Countries);
var resultByCountries = MotusElasticsearch.SearchByCountrieName(countries);
if(resultByCountries.Any())
{
result.AddRange(resultByCountries);
}
}
if (data.Genres != null && data.Genres.Any())
{
string genres = string.Join(",", data.Genres);
var resultByGenres = MotusElasticsearch.SearchByGenreTitle(genres);
if (result.Any() && resultByGenres.Any())
{
result.Intersect(resultByGenres);
}
else if (resultByGenres.Any())
{
result.AddRange(resultByGenres);
}
}
if (data.Translations != null && data.Translations.Any())
{
string translations = string.Join(",", data.Translations);
var resultByTranslations = MotusElasticsearch.SearchByTranslationTitle(translations);
if (result.Any() && resultByTranslations.Any())
{
result.Intersect(resultByTranslations);
}
else if (resultByTranslations.Any())
{
result.AddRange(resultByTranslations);
}
}
if (data.MinImdb != 0)
{
var resultByImdb = MotusElasticsearch.SearchByIMDB(data.MinImdb);
if (result.Any() && resultByImdb.Any())
{
result.Intersect(resultByImdb);
}
else if (resultByImdb.Any())
{
result.AddRange(resultByImdb);
}
}
if (data.MinKinopoisk != 0)
{
var resultByKinopoisk = MotusElasticsearch.SearchByKinopoiskRating(data.MinKinopoisk);
if (result.Any() && resultByKinopoisk.Any())
{
result.Intersect(resultByKinopoisk);
}
else if (resultByKinopoisk.Any())
{
result.AddRange(resultByKinopoisk);
}
}
if (data.MaxReliseDateValue != 0)
{
var resultByReliseDate = MotusElasticsearch.SearchByReliseDate(data.MinReliseDateValue,data.MaxReliseDateValue);
if (result.Any() && resultByReliseDate.Any())
{
result.Intersect(resultByReliseDate);
}
else if (resultByReliseDate.Any())
{
result.AddRange(resultByReliseDate);
}
}
return result;
}
c# .net
$endgroup$
closed as off-topic by πάντα ῥεῖ, t3chb0t, Jamal♦ Mar 16 at 2:26
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – πάντα ῥεῖ, t3chb0t, Jamal
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
$begingroup$
I do not like the repetition of the code and the use of slow LINQ. Cannot change search methods. It is necessary to optimize the code in this context. Thanks for any help.
public static IEnumerable<ElasticVideoMaterial> FilerResults(FilterData data)
{
List<ElasticVideoMaterial> result = new List<ElasticVideoMaterial>();
if (data.Countries != null && data.Countries.Any())
{
string countries = string.Join(",", data.Countries);
var resultByCountries = MotusElasticsearch.SearchByCountrieName(countries);
if(resultByCountries.Any())
{
result.AddRange(resultByCountries);
}
}
if (data.Genres != null && data.Genres.Any())
{
string genres = string.Join(",", data.Genres);
var resultByGenres = MotusElasticsearch.SearchByGenreTitle(genres);
if (result.Any() && resultByGenres.Any())
{
result.Intersect(resultByGenres);
}
else if (resultByGenres.Any())
{
result.AddRange(resultByGenres);
}
}
if (data.Translations != null && data.Translations.Any())
{
string translations = string.Join(",", data.Translations);
var resultByTranslations = MotusElasticsearch.SearchByTranslationTitle(translations);
if (result.Any() && resultByTranslations.Any())
{
result.Intersect(resultByTranslations);
}
else if (resultByTranslations.Any())
{
result.AddRange(resultByTranslations);
}
}
if (data.MinImdb != 0)
{
var resultByImdb = MotusElasticsearch.SearchByIMDB(data.MinImdb);
if (result.Any() && resultByImdb.Any())
{
result.Intersect(resultByImdb);
}
else if (resultByImdb.Any())
{
result.AddRange(resultByImdb);
}
}
if (data.MinKinopoisk != 0)
{
var resultByKinopoisk = MotusElasticsearch.SearchByKinopoiskRating(data.MinKinopoisk);
if (result.Any() && resultByKinopoisk.Any())
{
result.Intersect(resultByKinopoisk);
}
else if (resultByKinopoisk.Any())
{
result.AddRange(resultByKinopoisk);
}
}
if (data.MaxReliseDateValue != 0)
{
var resultByReliseDate = MotusElasticsearch.SearchByReliseDate(data.MinReliseDateValue,data.MaxReliseDateValue);
if (result.Any() && resultByReliseDate.Any())
{
result.Intersect(resultByReliseDate);
}
else if (resultByReliseDate.Any())
{
result.AddRange(resultByReliseDate);
}
}
return result;
}
c# .net
$endgroup$
I do not like the repetition of the code and the use of slow LINQ. Cannot change search methods. It is necessary to optimize the code in this context. Thanks for any help.
public static IEnumerable<ElasticVideoMaterial> FilerResults(FilterData data)
{
List<ElasticVideoMaterial> result = new List<ElasticVideoMaterial>();
if (data.Countries != null && data.Countries.Any())
{
string countries = string.Join(",", data.Countries);
var resultByCountries = MotusElasticsearch.SearchByCountrieName(countries);
if(resultByCountries.Any())
{
result.AddRange(resultByCountries);
}
}
if (data.Genres != null && data.Genres.Any())
{
string genres = string.Join(",", data.Genres);
var resultByGenres = MotusElasticsearch.SearchByGenreTitle(genres);
if (result.Any() && resultByGenres.Any())
{
result.Intersect(resultByGenres);
}
else if (resultByGenres.Any())
{
result.AddRange(resultByGenres);
}
}
if (data.Translations != null && data.Translations.Any())
{
string translations = string.Join(",", data.Translations);
var resultByTranslations = MotusElasticsearch.SearchByTranslationTitle(translations);
if (result.Any() && resultByTranslations.Any())
{
result.Intersect(resultByTranslations);
}
else if (resultByTranslations.Any())
{
result.AddRange(resultByTranslations);
}
}
if (data.MinImdb != 0)
{
var resultByImdb = MotusElasticsearch.SearchByIMDB(data.MinImdb);
if (result.Any() && resultByImdb.Any())
{
result.Intersect(resultByImdb);
}
else if (resultByImdb.Any())
{
result.AddRange(resultByImdb);
}
}
if (data.MinKinopoisk != 0)
{
var resultByKinopoisk = MotusElasticsearch.SearchByKinopoiskRating(data.MinKinopoisk);
if (result.Any() && resultByKinopoisk.Any())
{
result.Intersect(resultByKinopoisk);
}
else if (resultByKinopoisk.Any())
{
result.AddRange(resultByKinopoisk);
}
}
if (data.MaxReliseDateValue != 0)
{
var resultByReliseDate = MotusElasticsearch.SearchByReliseDate(data.MinReliseDateValue,data.MaxReliseDateValue);
if (result.Any() && resultByReliseDate.Any())
{
result.Intersect(resultByReliseDate);
}
else if (resultByReliseDate.Any())
{
result.AddRange(resultByReliseDate);
}
}
return result;
}
c# .net
c# .net
asked Mar 15 at 20:40
jhllkl kuylhjhllkl kuylh
1
1
closed as off-topic by πάντα ῥεῖ, t3chb0t, Jamal♦ Mar 16 at 2:26
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – πάντα ῥεῖ, t3chb0t, Jamal
If this question can be reworded to fit the rules in the help center, please edit the question.
closed as off-topic by πάντα ῥεῖ, t3chb0t, Jamal♦ Mar 16 at 2:26
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – πάντα ῥεῖ, t3chb0t, Jamal
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
add a comment |
0
active
oldest
votes
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes