Skip to content

Commit

Permalink
remove extra db call in upload
Browse files Browse the repository at this point in the history
  • Loading branch information
divyam234 committed Nov 5, 2023
1 parent 193bcb1 commit abb5029
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions services/upload.service.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,12 @@ func (us *UploadService) UploadFile(c *gin.Context) (*schemas.UploadPartOut, *ty

uploadId := c.Param("id")

var uploadPart []models.Upload

us.Db.Model(&models.Upload{}).Where("upload_id = ?", uploadId).Where("part_no = ?", uploadQuery.PartNo).
Where("user_id = ?", userId).
Find(&uploadPart)

if len(uploadPart) == 1 {
out := mapper.MapUploadSchema(&uploadPart[0])
return out, nil
}

file := c.Request.Body

fileSize := c.Request.ContentLength

fileName := uploadQuery.Filename

var msgId int

tokens, err := GetBotsToken(c, userId)

if err != nil {
Expand Down Expand Up @@ -156,16 +143,16 @@ func (us *UploadService) UploadFile(c *gin.Context) (*schemas.UploadPartOut, *ty

updates := res.(*tg.Updates)

msgId = updates.Updates[0].(*tg.UpdateMessageID).ID
message, ok := updates.Updates[1].(*tg.UpdateNewChannelMessage).Message.(*tg.Message)

if msgId == 0 {
if !ok {
return errors.New("failed to upload part")
}

partUpload := &models.Upload{
Name: fileName,
UploadId: uploadId,
PartId: msgId,
PartId: message.ID,
ChannelID: channelId,
Size: fileSize,
PartNo: uploadQuery.PartNo,
Expand Down

0 comments on commit abb5029

Please sign in to comment.