app that communicates with an SQL DB and the queries are quite slow, I'm trying to speed up the process because it's a mobile app.
1)
I made a data-type for the database entries:
public readonly struct DatabaseEntry
{
public readonly int Id;
public readonly DateTime Date;
public readonly TimeSpan OraIncepere;
public readonly TimeSpan OraFinal;
public readonly TimeSpan CursAlocat;
public readonly TimeSpan PregatireAlocat;
public readonly TimeSpan RecuperareAlocat;
public readonly TimeSpan Total;
public readonly string Observatii;
}
Should this be a class or a struct from an efficiency point of view?
2)
Are things in the connection string like:
Asynchronous Processing=true;Pooling=True;Min Pool Size=3;Max Pool Size=100;
relevant?
your mobile app is connected directly to the db?
Yes. I know it's not a good practice and I should do http requests but I don't have the time right now to do that logic
Np my question is just to understand, i dont think you will speed up application in that way.. where it is slow? when pushing queries? maybe the connection is disposed and reopened every time. are you using async pattern?
From an effeciency point of view, structs are faster to create and destroy, but not to copy. Anyway I really wouldn't care that much and I'd rather use classes/structs for they're main difference: structs are a value-type while classes are references
I'm doing an initial query to get all the elements from the DB and add them to a local list like: private async Task RefreshElementsAsync() => Entries = await _sql.GetAllElementsAsync().ConfigureAwait(false); —————————————— public async Task<List<DatabaseEntry>> GetAllElementsAsync() { IEnumerable<DatabaseEntry> result; await using (var conn = new SqlConnection(Secrets.ConnStr)) { result = await conn.QueryAsync<DatabaseEntry>($@"SELECT * FROM ""prezenta.{User}"""); } var elements = result.ToList(); return elements; } Using dapper btw
The only solution I can think of is caching the entries in a json and reading them. I did this for the user accounts because it would take a long time to query if the account entered is correct . I cache them when the app first starts in a json file and read them from it
so the problem is only here? slow to get initial data?
Yes. Adding or deleting entries is quite instant
var elements = result.ToList(); to ToListAsync
Oh I had no idea that existed lol Adding it, thanks
if QueryAsync retrieve the data, use ToList is ok, otherwise use tolistasync
Обсуждают сегодня