简体   繁体   English

每个用户django max文件夹编号

[英]django max folders number per user

I was thinking "Enterprise" :) In my Django 1.5 project if I will reach the maximum ext4 number of folders 我在想“企业”:)在我的Django 1.5项目中,如果我将达到最大ext4数量的文件夹

ext3: 31998* and ext4: 64000 ext3:31998 *和ext4:64000

And as far as I know with 63.999 folders there are problems, let's say it's an academic value and it's better not have such amount. 据我所知63.999文件夹有问题,让我们说这是一个学术价值,最好不要有这样的数量。

Eg users data folder. 例如用户数据文件夹。 Normally, I would solve like this 通常,我会这样解决

/data/users/id_user_1, /data/users/id_user_2, /data/users/id_user_N and / data / users / id_user_1,/ data / users / id_user_2,/ data / users / id_user_N和

user_data_path = settings.DATA_PATH + user.pk

With more than 40.000 users the above file system structure will collapse. 有超过40.000个用户,上述文件系统结构将崩溃。

What will it be a best practices/approach for this? 对此最佳实践/方法是什么?

Thanks! 谢谢!

You need to create sub-directories for multi-level structure to hold more directories. 您需要为多级结构创建子目录以容纳更多目录。

Simplistically, something like this assuming 40K is the limit. 简单地说,假设40K是这样的限制。

/data/users/0/        # for 1 <= pk <= 400000
             /1
             /400000
/data/users/1/        # for 400001 <= pk <= 800000
             /400001
             /800000
....

You can design for as many levels as you want and how to create/use the levels. 您可以根据需要设计多个级别以及如何创建/使用级别。

A possible approach is to partition the keyspace using simple integer division. 一种可能的方法是使用简单的整数除法来划分键空间。 Assuming that partition_size is your allowed maximum for a given directory, you can use: 假设partition_size是给定目录的允许最大值,您可以使用:

os.path.join(settings.DATA_PATH, str(user.pk // partition_size), str(user.pk))

Example with partition_size=200 : partition_size=200示例:

>>> fn(101)
'\\data\\users\\0\\101'
>>> fn(201)
'\\data\\users\\1\\201'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM