Skip to content

Commit ab083c8

Browse files
committed
Remove unused struct, fix duplicate table name
1 parent 1eff5bb commit ab083c8

File tree

10 files changed

+66
-88
lines changed

10 files changed

+66
-88
lines changed

models/conversations/comment.go

Lines changed: 41 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,11 @@ func (t CommentType) HasMailReplySupport() bool {
105105
return false
106106
}
107107

108-
// CommentMetaData stores metadata for a comment, these data will not be changed once inserted into database
109-
type CommentMetaData struct {
110-
ProjectColumnID int64 `json:"project_column_id,omitempty"`
111-
ProjectColumnTitle string `json:"project_column_title,omitempty"`
112-
ProjectTitle string `json:"project_title,omitempty"`
113-
}
114-
115-
// Comment represents a comment in commit and conversation page.
116-
// Comment struct should not contain any pointers unrelated to Conversation unless absolutely necessary.
108+
// ConversationComment represents a comment in commit and conversation page.
109+
// ConversationComment struct should not contain any pointers unrelated to Conversation unless absolutely necessary.
117110
// To have pointers outside of conversation, create another comment type (e.g. ConversationComment) and use a converter to load it in.
118111
// The database data for the comments however, for all comment types, are defined here.
119-
type Comment struct {
112+
type ConversationComment struct {
120113
ID int64 `xorm:"pk autoincr"`
121114
Type CommentType `xorm:"INDEX"`
122115

@@ -143,11 +136,11 @@ type Comment struct {
143136
}
144137

145138
func init() {
146-
db.RegisterModel(new(Comment))
139+
db.RegisterModel(new(ConversationComment))
147140
}
148141

149142
// LoadPoster loads comment poster
150-
func (c *Comment) LoadPoster(ctx context.Context) (err error) {
143+
func (c *ConversationComment) LoadPoster(ctx context.Context) (err error) {
151144
if c.Poster != nil {
152145
return nil
153146
}
@@ -165,7 +158,7 @@ func (c *Comment) LoadPoster(ctx context.Context) (err error) {
165158
}
166159

167160
// LoadReactions loads comment reactions
168-
func (c *Comment) LoadReactions(ctx context.Context, repo *repo_model.Repository) (err error) {
161+
func (c *ConversationComment) LoadReactions(ctx context.Context, repo *repo_model.Repository) (err error) {
169162
if c.Reactions != nil {
170163
return nil
171164
}
@@ -184,7 +177,7 @@ func (c *Comment) LoadReactions(ctx context.Context, repo *repo_model.Repository
184177
}
185178

186179
// AfterDelete is invoked from XORM after the object is deleted.
187-
func (c *Comment) AfterDelete(ctx context.Context) {
180+
func (c *ConversationComment) AfterDelete(ctx context.Context) {
188181
if c.ID <= 0 {
189182
return
190183
}
@@ -236,7 +229,7 @@ type CreateCommentOptions struct {
236229
}
237230

238231
// CreateComment creates comment with context
239-
func CreateComment(ctx context.Context, opts *CreateCommentOptions) (_ *Comment, err error) {
232+
func CreateComment(ctx context.Context, opts *CreateCommentOptions) (_ *ConversationComment, err error) {
240233
ctx, committer, err := db.TxContext(ctx)
241234
if err != nil {
242235
return nil, err
@@ -245,7 +238,7 @@ func CreateComment(ctx context.Context, opts *CreateCommentOptions) (_ *Comment,
245238

246239
e := db.GetEngine(ctx)
247240

248-
comment := &Comment{
241+
comment := &ConversationComment{
249242
Type: opts.Type,
250243
PosterID: opts.Doer.ID,
251244
Poster: opts.Doer,
@@ -267,8 +260,8 @@ func CreateComment(ctx context.Context, opts *CreateCommentOptions) (_ *Comment,
267260
}
268261

269262
// GetCommentByID returns the comment by given ID.
270-
func GetCommentByID(ctx context.Context, id int64) (*Comment, error) {
271-
c := new(Comment)
263+
func GetCommentByID(ctx context.Context, id int64) (*ConversationComment, error) {
264+
c := new(ConversationComment)
272265
has, err := db.GetEngine(ctx).ID(id).Get(c)
273266
if err != nil {
274267
return nil, err
@@ -301,43 +294,28 @@ func (opts FindCommentsOptions) ToConds() builder.Cond {
301294
cond = cond.And(builder.Eq{"conversation.repo_id": opts.RepoID})
302295
}
303296
if opts.ConversationID > 0 {
304-
cond = cond.And(builder.Eq{"comment.conversation_id": opts.ConversationID})
297+
cond = cond.And(builder.Eq{"conversation_comment.conversation_id": opts.ConversationID})
305298
} else if len(opts.ConversationIDs) > 0 {
306-
cond = cond.And(builder.In("comment.conversation_id", opts.ConversationIDs))
307-
}
308-
if opts.ReviewID > 0 {
309-
cond = cond.And(builder.Eq{"comment.review_id": opts.ReviewID})
299+
cond = cond.And(builder.In("conversation_comment.conversation_id", opts.ConversationIDs))
310300
}
311301
if opts.Since > 0 {
312-
cond = cond.And(builder.Gte{"comment.updated_unix": opts.Since})
302+
cond = cond.And(builder.Gte{"conversation_comment.updated_unix": opts.Since})
313303
}
314304
if opts.Before > 0 {
315-
cond = cond.And(builder.Lte{"comment.updated_unix": opts.Before})
305+
cond = cond.And(builder.Lte{"conversation_comment.updated_unix": opts.Before})
316306
}
317307
if opts.Type != CommentTypeUndefined {
318-
cond = cond.And(builder.Eq{"comment.type": opts.Type})
319-
}
320-
if opts.Line != 0 {
321-
cond = cond.And(builder.Eq{"comment.line": opts.Line})
322-
}
323-
if len(opts.TreePath) > 0 {
324-
cond = cond.And(builder.Eq{"comment.tree_path": opts.TreePath})
325-
}
326-
if opts.Invalidated.Has() {
327-
cond = cond.And(builder.Eq{"comment.invalidated": opts.Invalidated.Value()})
328-
}
329-
if opts.IsPull.Has() {
330-
cond = cond.And(builder.Eq{"conversation.is_pull": opts.IsPull.Value()})
308+
cond = cond.And(builder.Eq{"conversation_comment.type": opts.Type})
331309
}
332310
return cond
333311
}
334312

335313
// FindComments returns all comments according options
336314
func FindComments(ctx context.Context, opts *FindCommentsOptions) (CommentList, error) {
337-
comments := make([]*Comment, 0, 10)
315+
comments := make([]*ConversationComment, 0, 10)
338316
sess := db.GetEngine(ctx).Where(opts.ToConds())
339317
if opts.RepoID > 0 {
340-
sess.Join("INNER", "conversation", "conversation.id = comment.conversation_id")
318+
sess.Join("INNER", "conversation", "conversation.id = conversation_comment.conversation_id")
341319
}
342320

343321
if opts.Page != 0 {
@@ -347,28 +325,28 @@ func FindComments(ctx context.Context, opts *FindCommentsOptions) (CommentList,
347325
// WARNING: If you change this order you will need to fix createCodeComment
348326

349327
return comments, sess.
350-
Asc("comment.created_unix").
351-
Asc("comment.id").
328+
Asc("conversation_comment.created_unix").
329+
Asc("conversation_comment.id").
352330
Find(&comments)
353331
}
354332

355333
// CountComments count all comments according options by ignoring pagination
356334
func CountComments(ctx context.Context, opts *FindCommentsOptions) (int64, error) {
357335
sess := db.GetEngine(ctx).Where(opts.ToConds())
358336
if opts.RepoID > 0 {
359-
sess.Join("INNER", "conversation", "conversation.id = comment.conversation_id")
337+
sess.Join("INNER", "conversation", "conversation.id = conversation_comment.conversation_id")
360338
}
361-
return sess.Count(&Comment{})
339+
return sess.Count(&ConversationComment{})
362340
}
363341

364342
// UpdateCommentInvalidate updates comment invalidated column
365-
func UpdateCommentInvalidate(ctx context.Context, c *Comment) error {
343+
func UpdateCommentInvalidate(ctx context.Context, c *ConversationComment) error {
366344
_, err := db.GetEngine(ctx).ID(c.ID).Cols("invalidated").Update(c)
367345
return err
368346
}
369347

370-
// UpdateComment updates information of comment.
371-
func UpdateComment(ctx context.Context, c *Comment, contentVersion int, doer *user_model.User) error {
348+
// UpdateComment updates information of comment
349+
func UpdateComment(ctx context.Context, c *ConversationComment, contentVersion int, doer *user_model.User) error {
372350
ctx, committer, err := db.TxContext(ctx)
373351
if err != nil {
374352
return err
@@ -393,7 +371,7 @@ func UpdateComment(ctx context.Context, c *Comment, contentVersion int, doer *us
393371
}
394372

395373
// DeleteComment deletes the comment
396-
func DeleteComment(ctx context.Context, comment *Comment) error {
374+
func DeleteComment(ctx context.Context, comment *ConversationComment) error {
397375
e := db.GetEngine(ctx)
398376
if _, err := e.ID(comment.ID).NoAutoCondition().Delete(comment); err != nil {
399377
return err
@@ -418,11 +396,11 @@ func DeleteComment(ctx context.Context, comment *Comment) error {
418396

419397
// UpdateCommentsMigrationsByType updates comments' migrations information via given git service type and original id and poster id
420398
func UpdateCommentsMigrationsByType(ctx context.Context, tp structs.GitServiceType, originalAuthorID string, posterID int64) error {
421-
_, err := db.GetEngine(ctx).Table("comment").
422-
Join("INNER", "conversation", "conversation.id = comment.conversation_id").
399+
_, err := db.GetEngine(ctx).Table("conversation_comment").
400+
Join("INNER", "conversation", "conversation.id = conversation_comment.conversation_id").
423401
Join("INNER", "repository", "conversation.repo_id = repository.id").
424402
Where("repository.original_service_type = ?", tp).
425-
And("comment.original_author_id = ?", originalAuthorID).
403+
And("conversation_comment.original_author_id = ?", originalAuthorID).
426404
Update(map[string]any{
427405
"poster_id": posterID,
428406
"original_author": "",
@@ -431,7 +409,7 @@ func UpdateCommentsMigrationsByType(ctx context.Context, tp structs.GitServiceTy
431409
return err
432410
}
433411

434-
func UpdateAttachments(ctx context.Context, opts *CreateCommentOptions, comment *Comment) error {
412+
func UpdateAttachments(ctx context.Context, opts *CreateCommentOptions, comment *ConversationComment) error {
435413
attachments, err := repo_model.GetAttachmentsByUUIDs(ctx, opts.Attachments)
436414
if err != nil {
437415
return fmt.Errorf("getAttachmentsByUUIDs [uuids: %v]: %w", opts.Attachments, err)
@@ -449,7 +427,7 @@ func UpdateAttachments(ctx context.Context, opts *CreateCommentOptions, comment
449427
}
450428

451429
// LoadConversation loads the conversation reference for the comment
452-
func (c *Comment) LoadConversation(ctx context.Context) (err error) {
430+
func (c *ConversationComment) LoadConversation(ctx context.Context) (err error) {
453431
if c.Conversation != nil {
454432
return nil
455433
}
@@ -458,7 +436,7 @@ func (c *Comment) LoadConversation(ctx context.Context) (err error) {
458436
}
459437

460438
// LoadAttachments loads attachments (it never returns error, the error during `GetAttachmentsByCommentIDCtx` is ignored)
461-
func (c *Comment) LoadAttachments(ctx context.Context) error {
439+
func (c *ConversationComment) LoadAttachments(ctx context.Context) error {
462440
if len(c.Attachments) > 0 {
463441
return nil
464442
}
@@ -472,7 +450,7 @@ func (c *Comment) LoadAttachments(ctx context.Context) error {
472450
}
473451

474452
// UpdateAttachments update attachments by UUIDs for the comment
475-
func (c *Comment) UpdateAttachments(ctx context.Context, uuids []string) error {
453+
func (c *ConversationComment) UpdateAttachments(ctx context.Context, uuids []string) error {
476454
ctx, committer, err := db.TxContext(ctx)
477455
if err != nil {
478456
return err
@@ -494,16 +472,16 @@ func (c *Comment) UpdateAttachments(ctx context.Context, uuids []string) error {
494472
}
495473

496474
// HashTag returns unique hash tag for conversation.
497-
func (c *Comment) HashTag() string {
475+
func (c *ConversationComment) HashTag() string {
498476
return fmt.Sprintf("comment-%d", c.ID)
499477
}
500478

501-
func (c *Comment) hashLink() string {
479+
func (c *ConversationComment) hashLink() string {
502480
return "#" + c.HashTag()
503481
}
504482

505483
// HTMLURL formats a URL-string to the conversation-comment
506-
func (c *Comment) HTMLURL(ctx context.Context) string {
484+
func (c *ConversationComment) HTMLURL(ctx context.Context) string {
507485
err := c.LoadConversation(ctx)
508486
if err != nil { // Silently dropping errors :unamused:
509487
log.Error("LoadConversation(%d): %v", c.ConversationID, err)
@@ -518,7 +496,7 @@ func (c *Comment) HTMLURL(ctx context.Context) string {
518496
}
519497

520498
// APIURL formats a API-string to the conversation-comment
521-
func (c *Comment) APIURL(ctx context.Context) string {
499+
func (c *ConversationComment) APIURL(ctx context.Context) string {
522500
err := c.LoadConversation(ctx)
523501
if err != nil { // Silently dropping errors :unamused:
524502
log.Error("LoadConversation(%d): %v", c.ConversationID, err)
@@ -534,11 +512,11 @@ func (c *Comment) APIURL(ctx context.Context) string {
534512
}
535513

536514
// HasOriginalAuthor returns if a comment was migrated and has an original author.
537-
func (c *Comment) HasOriginalAuthor() bool {
515+
func (c *ConversationComment) HasOriginalAuthor() bool {
538516
return c.OriginalAuthor != "" && c.OriginalAuthorID != 0
539517
}
540518

541-
func (c *Comment) ConversationURL(ctx context.Context) string {
519+
func (c *ConversationComment) ConversationURL(ctx context.Context) string {
542520
err := c.LoadConversation(ctx)
543521
if err != nil { // Silently dropping errors :unamused:
544522
log.Error("LoadConversation(%d): %v", c.ConversationID, err)
@@ -554,12 +532,12 @@ func (c *Comment) ConversationURL(ctx context.Context) string {
554532
}
555533

556534
// InsertConversationComments inserts many comments of conversations.
557-
func InsertConversationComments(ctx context.Context, comments []*Comment) error {
535+
func InsertConversationComments(ctx context.Context, comments []*ConversationComment) error {
558536
if len(comments) == 0 {
559537
return nil
560538
}
561539

562-
conversationIDs := container.FilterSlice(comments, func(comment *Comment) (int64, bool) {
540+
conversationIDs := container.FilterSlice(comments, func(comment *ConversationComment) (int64, bool) {
563541
return comment.ConversationID, true
564542
})
565543

models/conversations/comment_list.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ import (
1212
)
1313

1414
// CommentList defines a list of comments
15-
type CommentList []*Comment
15+
type CommentList []*ConversationComment
1616

1717
// LoadPosters loads posters
1818
func (comments CommentList) LoadPosters(ctx context.Context) error {
1919
if len(comments) == 0 {
2020
return nil
2121
}
2222

23-
posterIDs := container.FilterSlice(comments, func(c *Comment) (int64, bool) {
23+
posterIDs := container.FilterSlice(comments, func(c *ConversationComment) (int64, bool) {
2424
return c.PosterID, c.Poster == nil && c.PosterID > 0
2525
})
2626

@@ -39,7 +39,7 @@ func (comments CommentList) LoadPosters(ctx context.Context) error {
3939

4040
// getConversationIDs returns all the conversation ids on this comment list which conversation hasn't been loaded
4141
func (comments CommentList) getConversationIDs() []int64 {
42-
return container.FilterSlice(comments, func(comment *Comment) (int64, bool) {
42+
return container.FilterSlice(comments, func(comment *ConversationComment) (int64, bool) {
4343
return comment.ConversationID, comment.Conversation == nil
4444
})
4545
}
@@ -109,7 +109,7 @@ func (comments CommentList) LoadConversations(ctx context.Context) error {
109109

110110
// getAttachmentCommentIDs only return the comment ids which possibly has attachments
111111
func (comments CommentList) getAttachmentCommentIDs() []int64 {
112-
return container.FilterSlice(comments, func(comment *Comment) (int64, bool) {
112+
return container.FilterSlice(comments, func(comment *ConversationComment) (int64, bool) {
113113
return comment.ID, comment.Type.HasAttachmentSupport()
114114
})
115115
}

models/conversations/conversation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ func (conversation *Conversation) loadReactions(ctx context.Context) (err error)
327327
}
328328

329329
// Cache comments to map
330-
comments := make(map[int64]*Comment)
330+
comments := make(map[int64]*ConversationComment)
331331
for _, comment := range conversation.Comments {
332332
comments[comment.ID] = comment
333333
}

models/conversations/conversation_list.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,26 +116,26 @@ func (conversations ConversationList) loadComments(ctx context.Context, cond bui
116116
return nil
117117
}
118118

119-
comments := make(map[int64][]*Comment, len(conversations))
119+
comments := make(map[int64][]*ConversationComment, len(conversations))
120120
conversationsIDs := conversations.getConversationIDs()
121121
left := len(conversationsIDs)
122122
for left > 0 {
123123
limit := db.DefaultMaxInSize
124124
if left < limit {
125125
limit = left
126126
}
127-
rows, err := db.GetEngine(ctx).Table("comment").
128-
Join("INNER", "conversation", "conversation.id = comment.conversation_id").
127+
rows, err := db.GetEngine(ctx).Table("conversation_comment").
128+
Join("INNER", "conversation", "conversation.id = conversation_comment.conversation_id").
129129
In("conversation.id", conversationsIDs[:limit]).
130130
Where(cond).
131131
NoAutoCondition().
132-
Rows(new(Comment))
132+
Rows(new(ConversationComment))
133133
if err != nil {
134134
return err
135135
}
136136

137137
for rows.Next() {
138-
var comment Comment
138+
var comment ConversationComment
139139
err = rows.Scan(&comment)
140140
if err != nil {
141141
if err1 := rows.Close(); err1 != nil {

models/conversations/conversation_update.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ func DeleteConversationsByRepoID(ctx context.Context, repoID int64) (attachmentP
278278
}
279279

280280
// Delete comments and attachments
281-
_, err = sess.In("conversation_id", conversationIDs).Delete(&Comment{})
281+
_, err = sess.In("conversation_id", conversationIDs).Delete(&ConversationComment{})
282282
if err != nil {
283283
return nil, err
284284
}
@@ -293,7 +293,7 @@ func DeleteConversationsByRepoID(ctx context.Context, repoID int64) (attachmentP
293293
return nil, err
294294
}
295295

296-
_, err = sess.In("dependent_conversation_id", conversationIDs).Delete(&Comment{})
296+
_, err = sess.In("dependent_conversation_id", conversationIDs).Delete(&ConversationComment{})
297297
if err != nil {
298298
return nil, err
299299
}

0 commit comments

Comments
 (0)