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

Method DeleteByLimit

models/document_history.go:193–224  ·  view source on GitHub ↗

根据文档id删除

(docId, limit int)

Source from the content-addressed store, hash-verified

191
192// 根据文档id删除
193func (history *DocumentHistory) DeleteByLimit(docId, limit int) (err error) {
194 if limit <= 0 {
195 return
196 }
197
198 filter := orm.NewOrm().QueryTable(history.TableNameWithPrefix()).Filter("document_id", docId)
199
200 var cnt int64
201 cnt, err = filter.Count()
202 if err != nil {
203 return
204 }
205
206 l := int64(limit)
207
208 if cnt > l {
209
210 var histories []DocumentHistory
211 var historyIds []interface{}
212
213 filter2 := filter.OrderBy("history_id").Limit(cnt - l)
214 filter2.All(&histories, "document_id", "version", "history_id")
215
216 for _, item := range histories {
217 ver := NewVersionControl(item.DocumentId, item.Version)
218 ver.DeleteVersion()
219 historyIds = append(historyIds, item.HistoryId)
220 }
221 filter.Filter("history_id__in", historyIds).Delete()
222 }
223 return
224}

Callers 1

ContentMethod · 0.95

Calls 7

TableNameWithPrefixMethod · 0.95
NewVersionControlFunction · 0.85
appendFunction · 0.50
CountMethod · 0.45
AllMethod · 0.45
DeleteVersionMethod · 0.45
DeleteMethod · 0.45

Tested by

no test coverage detected