I have a simple log table where I store things like what, who and when:
public class Logg
{
public int ID { get; set; }
public string Name { get; set; }
public string What { get; set; }
public DateTime When { get; set; }
}Ii'm wondering what is the best way of fetching this data from the db in the future when i have thousands and thousands of logs?
I have a webage where users can see the last 10 entries of the log. i don't need to change it in the future, so i'm thinking of if a simple fetch query of the last 10 is performant enough? Most likely it is and I shouldn't use much time on this, but i want to know for academic reasons.
This is my query:,
var logg = await _context.Loggs.OrderByDescending(d => d.When).Take(10).ToListAsync();
This will give me the 10 latest log entries. I'm worried that the process of ordering thousands of entries eventually would be expensive? An alternative could simply be to count the number of entries and take the last 10 id numbers since it starts at 1 (although deletions could mess this up. probably not the best idea). Another would be to not take 10 but do a linq and fetch on the latest month.