0

I am trying to find an efficient technique to differentiate between seen and unseen content per user. I have a table of specific files, but need to keep track of the user who accessed them and then display a notification if new files or content has been added.

I have considered creating a table that just keeps a member and file id and whether the record exists / has been seen and joining that table onto the files table, but I see that table growing exponentially quicker with every file change. Would a JSON decoded file be a better approach for every user who logs in? Or any other recommendations?

Edit: Making a DB to track timestamps of when the user seen the file, so if the file is updated, I will know that the user has not seen the updated file.

7
  • So you have a storage space problem, then? Nov 24, 2017 at 2:01
  • 1
    Yes, it will grow quickly as you keep the "seen" attribute for each file and user. But why worry? That's what databases are for. You can, also, archive content from time to time to reduce the size of the tables. Consider how email clients work and you can get some lessons useful for your case Nov 24, 2017 at 3:06
  • 2
    I don't see why this table would grow exponentially. If that would indeed be the case then Yes, you would have a problem. If it would grow linearly then I don't see why that would be a problem. Also, don't try to fix problems you don't have (yet). Nov 24, 2017 at 6:27
  • A properly indexed RDBMS will be faster and possibly use less storage than constantly serialising and deserialising a JSON file: whenever the user sees a new site you would have to rewrite the whole JSON file. You can design your code so that you can easily swap out the storage solution if it should become necessary in the future, e.g. with the Repository Pattern.
    – amon
    Nov 24, 2017 at 8:44
  • @RobertHarvey I dont have a space problem, but I am trying to efficient with the solution.
    – Ice76
    Nov 24, 2017 at 18:41

1 Answer 1

1

If you have M members storing F files, you'll need to store M × F rows in the general case.

Adding another member costs you F additional rows, and adding a file costs M additional rows. This is much much less than exponential growth.

The "seen" function is monotonic with time - once seen, a file never becomes unseen. So in the limit, most of those rows will be storing boolean True to indicate "seen". This lets you conveniently compress / summarize with a timestamp, by storing that a given member has seen all files older than a certain timestamp.

You can choose to relax the problem's constraints by only allowing unseen files to be read in reverse chronologic order, so rather than storing F bits for a member you store just a single timestamp.

You can choose to relax the problem by keeping detailed track of just a fixed window of K=100 messages near the seen/unseen border. A user who chooses to scroll outside the K-file window would automatically advance the window so older files get the summary marking of "seen" by advancing that timestamp. Then storage is reduced from M × F down to M × K, independent of however many millions of ancient files are in the system. The window would have a summary timestamp on the old side, and another on the new side, representing e.g. the large number of new files Alice hasn't seen when she has not used your system for some months.

1
  • Thanks for the input. I think I will make a timestamp of when the file is seen instead of seen or not. That way, I can easily compare which timestamp is greater, and then if the file is updated, display accordingly.
    – Ice76
    Nov 24, 2017 at 18:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.