appview: {db,issues}: remove unnecessary GetIssueId method #7

open
opened by boltless.me targeting master from feat/search

As issue.IssueId is already retrieved from NewIssue, We don't need GetIssueId to get last issue-id. Using same, last inserted issue-id would be better.

Signed-off-by: Seongmin Lee boltlessengineer@proton.me

Changed files
+7 -19
appview
db
issues
-6
appview/db/issues.go
··· 98 98 return issueAt, err 99 99 } 100 100 101 - func GetIssueId(e Execer, repoAt syntax.ATURI) (int, error) { 102 - var issueId int 103 - err := e.QueryRow(`select next_issue_id from repo_issue_seqs where repo_at = ?`, repoAt).Scan(&issueId) 104 - return issueId - 1, err 105 - } 106 - 107 101 func GetIssueOwnerDid(e Execer, repoAt syntax.ATURI, issueId int) (string, error) { 108 102 var ownerDid string 109 103 err := e.QueryRow(`select owner_did from issues where repo_at = ? and issue_id = ?`, repoAt, issueId).Scan(&ownerDid)
+7 -13
appview/issues/issues.go
··· 687 687 return 688 688 } 689 689 690 - err = db.NewIssue(tx, &db.Issue{ 690 + issue := &db.Issue{ 691 691 RepoAt: f.RepoAt, 692 692 Title: title, 693 693 Body: body, 694 694 OwnerDid: user.Did, 695 - }) 696 - if err != nil { 697 - log.Println("failed to create issue", err) 698 - rp.pages.Notice(w, "issues", "Failed to create issue.") 699 - return 700 695 } 701 - 702 - issueId, err := db.GetIssueId(rp.db, f.RepoAt) 696 + err = db.NewIssue(tx, issue) 703 697 if err != nil { 704 - log.Println("failed to get issue id", err) 698 + log.Println("failed to create issue", err) 705 699 rp.pages.Notice(w, "issues", "Failed to create issue.") 706 700 return 707 701 } ··· 723 717 Title: title, 724 718 Body: &body, 725 719 Owner: user.Did, 726 - IssueId: int64(issueId), 720 + IssueId: int64(issue.IssueId), 727 721 }, 728 722 }, 729 723 }) ··· 733 727 return 734 728 } 735 729 736 - err = db.SetIssueAt(rp.db, f.RepoAt, issueId, resp.Uri) 730 + err = db.SetIssueAt(rp.db, f.RepoAt, issue.IssueId, resp.Uri) 737 731 if err != nil { 738 732 log.Println("failed to set issue at", err) 739 733 rp.pages.Notice(w, "issues", "Failed to create issue.") ··· 744 738 err = rp.posthog.Enqueue(posthog.Capture{ 745 739 DistinctId: user.Did, 746 740 Event: "new_issue", 747 - Properties: posthog.Properties{"repo_at": f.RepoAt.String(), "issue_id": issueId}, 741 + Properties: posthog.Properties{"repo_at": f.RepoAt.String(), "issue_id": issue.IssueId}, 748 742 }) 749 743 if err != nil { 750 744 log.Println("failed to enqueue posthog event:", err) 751 745 } 752 746 } 753 747 754 - rp.pages.HxLocation(w, fmt.Sprintf("/%s/issues/%d", f.OwnerSlashRepo(), issueId)) 748 + rp.pages.HxLocation(w, fmt.Sprintf("/%s/issues/%d", f.OwnerSlashRepo(), issue.IssueId)) 755 749 return 756 750 } 757 751 }