Skip to content

Commit 5ba8ae1

Browse files
committed
Remove unnecessary data from Conversation
1 parent abc5d12 commit 5ba8ae1

File tree

7 files changed

+16
-302
lines changed

7 files changed

+16
-302
lines changed

models/conversations/conversation.go

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,13 @@ type Conversation struct {
115115

116116
IsLocked bool `xorm:"-"`
117117

118-
Comments CommentList `xorm:"-"`
119-
Attachments []*repo_model.Attachment `xorm:"-"`
120-
isAttachmentsLoaded bool `xorm:"-"`
118+
Comments CommentList `xorm:"-"`
121119

122120
CommitSha string `xorm:"VARCHAR(64)"`
123121
IsRead bool `xorm:"-"`
124122
}
125123

126-
// IssueIndex represents the issue index table
124+
// ConversationIndex represents the conversation index table
127125
type ConversationIndex db.ResourceIndex
128126

129127
func init() {
@@ -173,7 +171,7 @@ func GetConversationByID(ctx context.Context, id int64) (*Conversation, error) {
173171
return conversation, nil
174172
}
175173

176-
// GetIssueByIndex returns raw issue without loading attributes by index in a repository.
174+
// GetConversationByIndex returns raw conversation without loading attributes by index in a repository.
177175
func GetConversationByIndex(ctx context.Context, repoID, index int64) (*Conversation, error) {
178176
if index < 1 {
179177
return nil, ErrConversationNotExist{}
@@ -202,10 +200,6 @@ func (conversation *Conversation) LoadAttributes(ctx context.Context) (err error
202200
return err
203201
}
204202

205-
if err = conversation.LoadAttachments(ctx); err != nil {
206-
return err
207-
}
208-
209203
if err = conversation.loadComments(ctx); err != nil {
210204
return err
211205
}
@@ -228,51 +222,38 @@ func (conversation *Conversation) LoadRepo(ctx context.Context) (err error) {
228222
return nil
229223
}
230224

231-
func (conversation *Conversation) LoadAttachments(ctx context.Context) (err error) {
232-
if conversation.isAttachmentsLoaded || conversation.Attachments != nil {
233-
return nil
234-
}
235-
236-
conversation.Attachments, err = repo_model.GetAttachmentsByConversationID(ctx, conversation.ID)
237-
if err != nil {
238-
return fmt.Errorf("getAttachmentsByConversationID [%d]: %w", conversation.ID, err)
239-
}
240-
conversation.isAttachmentsLoaded = true
241-
return nil
242-
}
243-
244225
// GetConversationIDsByRepoID returns all conversation ids by repo id
245226
func GetConversationIDsByRepoID(ctx context.Context, repoID int64) ([]int64, error) {
246227
ids := make([]int64, 0, 10)
247228
err := db.GetEngine(ctx).Table("conversation").Cols("id").Where("repo_id = ?", repoID).Find(&ids)
248229
return ids, err
249230
}
250231

251-
// GetConversationsByIDs return issues with the given IDs.
232+
// GetConversationsByIDs return conversations with the given IDs.
252233
// If keepOrder is true, the order of the returned Conversations will be the same as the given IDs.
253-
func GetConversationsByIDs(ctx context.Context, issueIDs []int64, keepOrder ...bool) (ConversationList, error) {
254-
issues := make([]*Conversation, 0, len(issueIDs))
234+
func GetConversationsByIDs(ctx context.Context, conversationIDs []int64, keepOrder ...bool) (ConversationList, error) {
235+
conversations := make([]*Conversation, 0, len(conversationIDs))
255236

256-
if err := db.GetEngine(ctx).In("id", issueIDs).Find(&issues); err != nil {
237+
if err := db.GetEngine(ctx).In("id", conversationIDs).Find(&conversations); err != nil {
257238
return nil, err
258239
}
259240

260241
if len(keepOrder) > 0 && keepOrder[0] {
261-
m := make(map[int64]*Conversation, len(issues))
242+
m := make(map[int64]*Conversation, len(conversations))
262243
appended := container.Set[int64]{}
263-
for _, issue := range issues {
264-
m[issue.ID] = issue
244+
for _, conversation := range conversations {
245+
m[conversation.ID] = conversation
265246
}
266-
issues = issues[:0]
267-
for _, id := range issueIDs {
268-
if issue, ok := m[id]; ok && !appended.Contains(id) { // make sure the id is existed and not appended
247+
conversations = conversations[:0]
248+
for _, id := range conversationIDs {
249+
if conversation, ok := m[id]; ok && !appended.Contains(id) { // make sure the id is existed and not appended
269250
appended.Add(id)
270-
issues = append(issues, issue)
251+
conversations = append(conversations, conversation)
271252
}
272253
}
273254
}
274255

275-
return issues, nil
256+
return conversations, nil
276257
}
277258

278259
func GetConversationByCommitID(ctx context.Context, commitID string) (*Conversation, error) {
@@ -318,7 +299,7 @@ func (conversation *Conversation) HTMLURL() string {
318299
return fmt.Sprintf("%s/%s/%s", conversation.Repo.HTMLURL(), "commit", conversation.CommitSha)
319300
}
320301

321-
// APIURL returns the absolute APIURL to this issue.
302+
// APIURL returns the absolute APIURL to this conversation.
322303
func (conversation *Conversation) APIURL(ctx context.Context) string {
323304
if conversation.Repo == nil {
324305
err := conversation.LoadRepo(ctx)

models/conversations/conversation_list.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,6 @@ func (conversations ConversationList) LoadAttachments(ctx context.Context) (err
108108
left -= limit
109109
conversationsIDs = conversationsIDs[limit:]
110110
}
111-
112-
for _, conversation := range conversations {
113-
conversation.Attachments = attachments[conversation.ID]
114-
conversation.isAttachmentsLoaded = true
115-
}
116111
return nil
117112
}
118113

models/conversations/conversation_update.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -283,18 +283,6 @@ func DeleteConversationsByRepoID(ctx context.Context, repoID int64) (attachmentP
283283
return nil, err
284284
}
285285

286-
// Dependencies for conversations in this repository
287-
_, err = sess.In("conversation_id", conversationIDs).Delete(&ConversationDependency{})
288-
if err != nil {
289-
return nil, err
290-
}
291-
292-
// Delete dependencies for conversations in other repositories
293-
_, err = sess.In("dependency_id", conversationIDs).Delete(&ConversationDependency{})
294-
if err != nil {
295-
return nil, err
296-
}
297-
298286
_, err = sess.In("conversation_id", conversationIDs).Delete(&ConversationUser{})
299287
if err != nil {
300288
return nil, err

models/conversations/dependency.go

Lines changed: 0 additions & 222 deletions
This file was deleted.

0 commit comments

Comments
 (0)