您是否考虑过使用 Gravatar(如 stackoverflow)来存储用户图像?这似乎是一个很酷的主意!如果您有兴趣,请访问 www.gravatar.com。 Gravatar 代表全球公认的头像。
我建议将用户信息和图像存储在单独的表中。选择是显而易见的,因为用户和图像之间存在一对多的关系。但是,您可以使用变体来提高性能并避免每次需要显示用户数据时进行连接。
User(userID, loginName, loginPwd)
UserImages(imageID, userID, image,type)
UserImages 的 image 属性将是一个二进制对象,用于存储完整图像或文件系统上某个位置的 url。在第二种情况下,您需要代码来获取图像(如果需要)。 type 属性采用值“主要个人资料”、“主要头像”、“其他个人资料”
如果预计图片的数量会很大,你可以修改设计如下
User(userID, loginName, loginPwd, profileImageID, profileImage)
UserImages(imageID, userID, image,type)
用于填充 profileImageID 和 ProfileImage 的 SQL
Update User T1
set (profileImageID, profileImage) = (Select imageID, image
from UserImages T2
where T1.userID = T2.userID
and T2.type='primary profile'
)
它可能看起来像用户表中的冗余数据存储。这个想法有时被用来通过避免连接来提高性能。此外,您需要通过将 profileImageID 设置为 userImages 表的 FK,确保不会在用户表上为 profileImageID 和 profileImage 列发生直接插入。这仍然会导致 profileImage 对恶意更新开放。你需要特殊的代码来处理它。如果您希望成为下一个互联网红人,您需要做这一切!一切顺利,希望你能成为其中的一员!