mirror of
https://github.com/eyebluecn/tank.git
synced 2024-04-21 12:32:16 +00:00
fix: fix the bug for file size.
This commit is contained in:
@@ -484,6 +484,26 @@ func (this *MatterDao) SizeByPuuidAndUserUuid(matterUuid string, userUuid string
|
||||
return sumSize
|
||||
}
|
||||
|
||||
func (this *MatterDao) SizeByPuuidAndSpaceUuid(matterUuid string, spaceUuid string) int64 {
|
||||
|
||||
var wp = &builder.WherePair{Query: "puuid = ? AND space_uuid = ?", Args: []interface{}{matterUuid, spaceUuid}}
|
||||
|
||||
var count int64
|
||||
db := core.CONTEXT.GetDB().Model(&Matter{}).Where(wp.Query, wp.Args...).Count(&count)
|
||||
if count == 0 {
|
||||
return 0
|
||||
}
|
||||
|
||||
var sumSize int64
|
||||
db = core.CONTEXT.GetDB().Model(&Matter{}).Where(wp.Query, wp.Args...).Select("SUM(size)")
|
||||
this.PanicError(db.Error)
|
||||
row := db.Row()
|
||||
err := row.Scan(&sumSize)
|
||||
core.PanicError(err)
|
||||
|
||||
return sumSize
|
||||
}
|
||||
|
||||
// delete a file from db and disk.
|
||||
func (this *MatterDao) Delete(matter *Matter) {
|
||||
|
||||
|
||||
@@ -564,10 +564,9 @@ func (this *MatterService) ComputeRouteSize(matterUuid string, user *User, space
|
||||
//if to root directory, then update to user's info.
|
||||
if matterUuid == MATTER_ROOT {
|
||||
|
||||
size := this.matterDao.SizeByPuuidAndUserUuid(MATTER_ROOT, user.Uuid)
|
||||
size := this.matterDao.SizeByPuuidAndSpaceUuid(MATTER_ROOT, space.Uuid)
|
||||
|
||||
db := core.CONTEXT.GetDB().Model(&Space{}).Where("uuid = ?", space.Uuid).Update("total_size", size)
|
||||
this.PanicError(db.Error)
|
||||
this.spaceDao.UpdateTotalSize(space.Uuid, size)
|
||||
|
||||
//update user total size info in cache.
|
||||
space.TotalSize = size
|
||||
@@ -580,12 +579,11 @@ func (this *MatterService) ComputeRouteSize(matterUuid string, user *User, space
|
||||
//only compute dir
|
||||
if matter.Dir {
|
||||
//compute the total size.
|
||||
size := this.matterDao.SizeByPuuidAndUserUuid(matterUuid, user.Uuid)
|
||||
size := this.matterDao.SizeByPuuidAndSpaceUuid(matterUuid, space.Uuid)
|
||||
|
||||
//when changed, we update
|
||||
if matter.Size != size {
|
||||
db := core.CONTEXT.GetDB().Model(&Matter{}).Where("uuid = ?", matterUuid).Update("size", size)
|
||||
this.PanicError(db.Error)
|
||||
this.spaceDao.UpdateTotalSize(space.Uuid, size)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -617,22 +615,20 @@ func (this *MatterService) ComputeDirSize(dirMatter *Matter, user *User, space *
|
||||
//if to root directory, then update to user's info.
|
||||
if dirMatter.Uuid == MATTER_ROOT {
|
||||
|
||||
size := this.matterDao.SizeByPuuidAndUserUuid(MATTER_ROOT, user.Uuid)
|
||||
size := this.matterDao.SizeByPuuidAndSpaceUuid(MATTER_ROOT, space.Uuid)
|
||||
|
||||
db := core.CONTEXT.GetDB().Model(&User{}).Where("uuid = ?", user.Uuid).Update("total_size", size)
|
||||
this.PanicError(db.Error)
|
||||
this.spaceDao.UpdateTotalSize(space.Uuid, size)
|
||||
|
||||
//update user total size info in cache.
|
||||
space.TotalSize = size
|
||||
} else {
|
||||
|
||||
//compute self.
|
||||
size := this.matterDao.SizeByPuuidAndUserUuid(dirMatter.Uuid, user.Uuid)
|
||||
size := this.matterDao.SizeByPuuidAndSpaceUuid(dirMatter.Uuid, user.Uuid)
|
||||
|
||||
//when changed, we update
|
||||
if dirMatter.Size != size {
|
||||
db := core.CONTEXT.GetDB().Model(&Matter{}).Where("uuid = ?", dirMatter.Uuid).Update("size", size)
|
||||
this.PanicError(db.Error)
|
||||
this.spaceDao.UpdateTotalSize(space.Uuid, size)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -132,6 +132,11 @@ func (this *SpaceDao) Save(space *Space) *Space {
|
||||
return space
|
||||
}
|
||||
|
||||
func (this *SpaceDao) UpdateTotalSize(spaceUuid string, totalSize int64) {
|
||||
db := core.CONTEXT.GetDB().Model(&Space{}).Where("uuid = ?", spaceUuid).Update("total_size", totalSize)
|
||||
this.PanicError(db.Error)
|
||||
}
|
||||
|
||||
func (this *SpaceDao) Delete(space *Space) {
|
||||
|
||||
db := core.CONTEXT.GetDB().Delete(&space)
|
||||
|
||||
Reference in New Issue
Block a user