my brainer for tonight is how to refactor this snippet to work with high performance if 1 million items are in. it's about books ratings.
public class Book
{
public string Title { get; set; }
public double Upvotes { get; set; }
public double Downvotes { get; set; }
public double PublisherStars { get; set; }
}
public IList<Book> TopRankList(IList<Book> books, int rankListLength)
{
var rankedBooks = (
from book in books
let readerVotes = book.Upvotes - book.Downvotes
let rank = (book.PublisherStars / 10 * 0.5) + (readerVotes * 0.5)
orderby rank descending
select book
).Take(rankListLength);
return rankedBooks.ToList();
}
I rewrote a foreach code in parallel, the execution speed improved from 35 seconds to 7 seconds.
If I were you, I would use stored procedure; then I would use a separate table (or view) based on the score (complex you use) that would automatically update every 24 hours and update the list.
We're a place where coders share, stay up-to-date and grow their careers.
Top comments (2)
my brainer for tonight is how to refactor this snippet to work with high performance if 1 million items are in. it's about books ratings.
Hello
I rewrote a foreach code in parallel, the execution speed improved from 35 seconds to 7 seconds.
If I were you, I would use stored procedure; then I would use a separate table (or view) based on the score (complex you use) that would automatically update every 24 hours and update the list.