Skip to content

Commit

Permalink
refactor: Purge share cache entry post delete
Browse files Browse the repository at this point in the history
  • Loading branch information
divyam234 committed Sep 16, 2024
1 parent 99bf608 commit 286baca
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func NewRun() *cobra.Command {
duration.DurationVar(runCmd.Flags(), &config.CronJobs.FolderSizeInterval, "cronjobs-folder-size-interval", 2*time.Hour, "Folder size update interval")

runCmd.Flags().IntVar(&config.Cache.MaxSize, "cache-max-size", 10*1024*1024, "Max Cache max size (memory)")
runCmd.Flags().StringVar(&config.Cache.RedisAddr, "cache-redis-addr", "localhost:6379", "Redis address")
runCmd.Flags().StringVar(&config.Cache.RedisAddr, "cache-redis-addr", "", "Redis address")
runCmd.Flags().StringVar(&config.Cache.RedisPass, "cache-redis-pass", "", "Redis password")

runCmd.Flags().IntVarP(&config.Log.Level, "log-level", "", -1, "Logging level")
Expand Down
2 changes: 1 addition & 1 deletion internal/tgc/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func GetLocation(ctx context.Context, client *tg.Client, channelId int64, partId
}

func CalculateChunkSize(start, end int64) int64 {
chunkSize := int64(512 * 1024)
chunkSize := int64(1024 * 1024)

for chunkSize > 1024 && chunkSize > (end-start) {
chunkSize /= 2
Expand Down
9 changes: 8 additions & 1 deletion pkg/services/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,10 +473,17 @@ func (fs *FileService) GetShareByFileId(fileId string, userId int64) (*schemas.F

func (fs *FileService) DeleteShare(fileId string, userId int64) *types.AppError {

if err := fs.db.Where("file_id = ?", fileId).Where("user_id = ?", userId).Delete(&models.FileShare{}).Error; err != nil {
var deletedShare models.FileShare

if err := fs.db.Clauses(clause.Returning{}).Where("file_id = ?", fileId).Where("user_id = ?", userId).
Delete(&deletedShare).Error; err != nil {
return &types.AppError{Error: err}
}

if deletedShare.ID != "" {
fs.cache.Delete(fmt.Sprintf("shares:%s", deletedShare.ID))
}

return nil
}

Expand Down

0 comments on commit 286baca

Please sign in to comment.