0

I'm working on an application that imports video files and lets the user browse them and filter them based on various conditions. By importing I mean creating instances of my VideoFile model class and storing them in a DB table. Once hundreds of files are there, the user wants to browse them.

Now, the first choice they have in the UI is to select a DateRecorded, which calls a GetFilesByDate(Date date) method on my data access class. This method will query the SQL database, asking only for files with the given date.

On top of that, I need to filter files by, let's say, FrameRate, Resolution or UserRating. This would place additional criteria on the files already filtered by their date. I'm deciding which road to take:

  1. Only query the DB for a new set of files when the desired DateRecorded changes. Handle all subsequent filtering manually in C# code, by iterating over the stored collection of _filesForSelectedDay and testing them against current additional rules.
  2. Query the DB each time any little filter changes, asking for a smaller and very specific set of files more often.

Which one would you choose, or even better, any thoughts on pros and cons of either of those?

Some additional points:

  • A query in GetFilesByDate is expected to return tens of items, so it's not very expensive to store the result in a collection always sitting in memory.
  • Later down the road I might want to select files not just for a specific day, but let's say for the entire month. This may give hundreds or thousands of items. This actually makes me lean towards option two.
  • The data access layer is not yet implemented. I just have a dummy class implementing the required interface, but storing the data in a in-memory collection instead of working with any kind of DB.
  • Once I'm there, I'll almost certainly use SQLite and store the database in a local file.
4

2 回答 2

1

如果您已经获得了大量数据,则无需再次查询数据库以获取该集合的子。只需将其存储在一个对象中,您可以根据用户对搜索查询的细化进行查询。

于 2013-10-27T11:58:17.987 回答
1

就个人而言,我每次都会去数据库,直到证明不切实际。如果是少量数据,那么开销也应该很小。当它变大时,数据库就会自己出现。尽管往返可能需要花费,但您不太可能编写比 DB 更好的代码。使用数据库,您的数据将始终保持一致和最新。

如果您发现您对 BD 的打击太大,那么您可以尝试缓存您的数据并计算您是否已经拥有部分或全部数据,以节省时间。但是,您需要处理老化和一致性问题。然后,您还拥有内存塞满可用于其他事情的数据的服务器!

基本上,在它成为问题之前,只需使用数据库并将精力用于遇到的实际问题,而不是可能的问题。

于 2013-10-27T13:10:13.673 回答