Is there a clear and more efficient replacement than a loop that checks all records?

I have a C # list that is populating from a database. So far its only 1400 records, but I expect it to grow LOT .. Usually I do validation for new data across the whole list .. What I am trying to figure out is is it faster to just clear the list and reload all data from the table, or will it check each entry is faster.

Intuition tells me that the dump and load method will be faster, but I decided to check first ...

+2


a source to share


5 answers


If my understanding is correct, you still have to load the list from MySql and it is very important that the list in memory is updated, right? So the only problem you are talking about is the dummy in the list memory.

Well, normally I would try to profile the different behaviors first, see what works best.



But as you state, I think that being clear and recreated should be faster than systematic checking and updating.

+1


a source


Need to reset and reboot. I base this advice solely on my (perhaps unfounded) fear of your code checking for new data.



+1


a source


Depends on how slow the load is. I would say that accessing something in memory will always be faster than loading from the DB. However, you need to do your calculations.

Remember, you don't need to optimize without numbers to support you.

0


a source


If the database does not get hit several times per hour, then permanently reload the data from the database. Offloding is like a big part of working with the database, as it is designed to make full use of system resources.

0


a source


Add the "InsertedTime" column to your database. Update these lines periodically with InsertedTime> ListCreatedTime (variable in your application)

This assumes the db data is not being deleted

If you want to handle db changes like update and delete. You can better set flags in your db. Later, when you have updated your list, you can delete your entries from your application.

But anyway project your dump and load method and compare it to this to see which is faster in your scenario.

0


a source







All Articles