From 5bcc7b3ff591a43a38871b63344a6851bed9453c Mon Sep 17 00:00:00 2001 From: liuzx Date: Wed, 15 Jun 2022 15:28:09 +0800 Subject: [PATCH] update --- models/attachment.go | 91 ----------------------------------------- routers/repo/dataset.go | 4 +- 2 files changed, 2 insertions(+), 93 deletions(-) diff --git a/models/attachment.go b/models/attachment.go index 2bc405b01..6fb98a07d 100755 --- a/models/attachment.go +++ b/models/attachment.go @@ -664,94 +664,3 @@ func Attachments(opts *AttachmentsOptions) ([]*AttachmentInfo, int64, error) { return attachments, count, nil } - -func MyFvAttachments(opts *AttachmentsOptions) ([]*AttachmentInfo, int64, error) { - sess := x.NewSession() - defer sess.Close() - - var cond = builder.NewCond() - if opts.NeedDatasetIDs { - cond = cond.And( - builder.In("attachment.dataset_id", opts.DatasetIDs), - ) - } - - if opts.UploaderID > 0 { - cond = cond.And( - builder.Eq{"attachment.uploader_id": opts.UploaderID}, - ) - } - - if (opts.Type) >= 0 { - cond = cond.And( - builder.Eq{"attachment.type": opts.Type}, - ) - } - - if opts.NeedIsPrivate { - cond = cond.And( - builder.Eq{"attachment.is_private": opts.IsPrivate}, - ) - } - if opts.RecommendOnly { - cond = cond.And(builder.In("attachment.id", builder.Select("attachment.id"). - From("attachment"). - Join("INNER", "dataset", "attachment.dataset_id = dataset.id and dataset.recommend=true"))) - } - - if opts.JustNeedZipFile { - var DecompressState []int32 - DecompressState = append(DecompressState, DecompressStateDone, DecompressStateIng, DecompressStateFailed) - cond = cond.And( - builder.In("attachment.decompress_state", DecompressState), - ) - } - - var count int64 - var err error - if len(opts.Keyword) == 0 { - count, err = sess.Where(cond).Count(new(Attachment)) - } else { - lowerKeyWord := strings.ToLower(opts.Keyword) - - cond = cond.And(builder.Or(builder.Like{"LOWER(attachment.name)", lowerKeyWord}, builder.Like{"LOWER(attachment.description)", lowerKeyWord})) - count, err = sess.Table(&Attachment{}).Where(cond).Count(new(AttachmentInfo)) - - } - - if err != nil { - return nil, 0, fmt.Errorf("Count: %v", err) - } - - sess.OrderBy("attachment.created_unix DESC") - attachments := make([]*AttachmentInfo, 0) - if err := sess.Table(&Attachment{}).Where(cond). - Find(&attachments); err != nil { - return nil, 0, fmt.Errorf("Find: %v", err) - } - - if opts.NeedRepoInfo { - for _, attachment := range attachments { - dataset, err := GetDatasetByID(attachment.DatasetID) - if err != nil { - return nil, 0, fmt.Errorf("GetDatasetByID failed error: %v", err) - } - attachment.Recommend = dataset.Recommend - repo, err := GetRepositoryByID(dataset.RepoID) - if err == nil { - attachment.Repo = repo - } else { - return nil, 0, fmt.Errorf("GetRepositoryByID failed error: %v", err) - } - user, err := GetUserByID(attachment.UploaderID) - if err == nil { - attachment.RelAvatarLink = user.RelAvatarLink() - attachment.UserName = user.Name - } else { - return nil, 0, fmt.Errorf("GetUserByID failed error: %v", err) - } - } - } - - return attachments, count, nil -} diff --git a/routers/repo/dataset.go b/routers/repo/dataset.go index 4c1baf740..d3ae1624b 100755 --- a/routers/repo/dataset.go +++ b/routers/repo/dataset.go @@ -485,7 +485,7 @@ func MyFavoriteDataset(ctx *context.Context) { } } - NotColDatasets, NotColcount, err := models.MyFvAttachments(&models.AttachmentsOptions{ + NotColDatasets, NotColcount, err := models.Attachments(&models.AttachmentsOptions{ Keyword: keyword, NeedDatasetIDs: true, DatasetIDs: NotColDatasetIDs, @@ -502,7 +502,7 @@ func MyFavoriteDataset(ctx *context.Context) { return } //If is collaborator, there is no need to determine whether the dataset is private or public - IsColDatasets, IsColcount, err := models.MyFvAttachments(&models.AttachmentsOptions{ + IsColDatasets, IsColcount, err := models.Attachments(&models.AttachmentsOptions{ Keyword: keyword, NeedDatasetIDs: true, DatasetIDs: IsColDatasetIDs,