train
train

Reputation: 610

how to limit user storage space php

I can't figure out the best way to limit a user's storage space on my php based app. I found another question but it doesn't seem to be an optimal way to handle this problem. The answers for that question suggest running a mysql SUM command to get the space a user is currently using. Is this efficient? What do other people usually do?

My case involves storing images for users. The images are loaded onto a cloud storage provider and I keep a record of the file size and name in my local database. Let's say that the maximum space a user gets is 10 GB. If each image is 300 kb after compression, that would be ~33,000 images per user. If there are 1,000 users, that would be ~33,000,000 images and thus ~33,000,000 rows in a table. This question suggests that the sum command is kinda slow when that many rows are considered.

Another option I thought of would be to increment and decrement a counter value every time an image is uploaded or deleted, but this might run into consistency and syncing problems. hm...

Upvotes: 0

Views: 414

Answers (1)

Ming M Zheng
Ming M Zheng

Reputation: 304

I think incrementing and decrementing a counter value# will be the solution. To ensure consistency, you can run a cronjob to query a slave database and sync the value at a certain period of time (or run the script when you are maintaining the database). I follow this way, for now, and so far so good.

Upvotes: 1

Related Questions