MCPcopy Index your code
hub / github.com/TruthHun/BookStack / FindToPager

Method FindToPager

models/attachment.go:83–125  ·  view source on GitHub ↗

分页查询附件

(pageIndex, pageSize int)

Source from the content-addressed store, hash-verified

81
82//分页查询附件
83func (m *Attachment) FindToPager(pageIndex, pageSize int) (attachList []*AttachmentResult, totalCount int64, err error) {
84 o := orm.NewOrm()
85
86 totalCount, err = o.QueryTable(m.TableNameWithPrefix()).Count()
87 if err != nil {
88 return
89 }
90
91 offset := (pageIndex - 1) * pageSize
92
93 var list []*Attachment
94 _, err = o.QueryTable(m.TableNameWithPrefix()).OrderBy("-attachment_id").Offset(offset).Limit(pageSize).All(&list)
95
96 if err != nil {
97 return
98 }
99
100 for _, item := range list {
101 attach := &AttachmentResult{}
102 attach.Attachment = *item
103 attach.FileShortSize = utils.FormatBytes(int64(attach.FileSize))
104
105 book := NewBook()
106 if e := o.QueryTable(book.TableNameWithPrefix()).Filter("book_id", item.BookId).One(book, "book_name", "identify"); e == nil {
107 attach.BookName = book.BookName
108 attach.BookIdentify = book.Identify
109 } else {
110 attach.BookName = "[不存在]"
111 }
112
113 doc := NewDocument()
114 if e := o.QueryTable(doc.TableNameWithPrefix()).Filter("document_id", item.DocumentId).One(doc, "document_name", "identify"); e == nil {
115 attach.DocumentName = doc.DocumentName
116 attach.DocIdentify = doc.Identify
117 } else {
118 attach.DocumentName = "[不存在]"
119 }
120 attach.LocalHttpPath = strings.Replace(item.FilePath, "\\", "/", -1)
121 attachList = append(attachList, attach)
122 }
123
124 return
125}

Callers

nothing calls this directly

Calls 10

TableNameWithPrefixMethod · 0.95
TableNameWithPrefixMethod · 0.95
TableNameWithPrefixMethod · 0.95
FormatBytesFunction · 0.92
NewBookFunction · 0.85
NewDocumentFunction · 0.85
appendFunction · 0.50
CountMethod · 0.45
AllMethod · 0.45
ReplaceMethod · 0.45

Tested by

no test coverage detected