summaryrefslogtreecommitdiffstats
path: root/models/repo.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2017-10-02 00:52:35 +0800
committerLauris BH <lauris@nix.lv>2017-10-01 19:52:35 +0300
commita8717e5e3ace4dd226547faae9c3a44616bbf6f0 (patch)
tree524dc024dec64131406486556951a53655ad8510 /models/repo.go
parent1ad902d5298202d5be14fd5a9c8ed6ce781a23c8 (diff)
downloadgitea-a8717e5e3ace4dd226547faae9c3a44616bbf6f0.tar.gz
gitea-a8717e5e3ace4dd226547faae9c3a44616bbf6f0.zip
Use AfterLoad instead of AfterSet on Structs (#2628)
* use AfterLoad instead of AfterSet on Structs * fix the comments on AfterLoad * fix the comments on action AfterLoad
Diffstat (limited to 'models/repo.go')
-rw-r--r--models/repo.go31
1 files changed, 12 insertions, 19 deletions
diff --git a/models/repo.go b/models/repo.go
index 22a3a83229..6b457863c8 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -216,25 +216,18 @@ type Repository struct {
UpdatedUnix int64 `xorm:"INDEX updated"`
}
-// AfterSet is invoked from XORM after setting the value of a field of this object.
-func (repo *Repository) AfterSet(colName string, _ xorm.Cell) {
- switch colName {
- case "default_branch":
- // FIXME: use models migration to solve all at once.
- if len(repo.DefaultBranch) == 0 {
- repo.DefaultBranch = "master"
- }
- case "num_closed_issues":
- repo.NumOpenIssues = repo.NumIssues - repo.NumClosedIssues
- case "num_closed_pulls":
- repo.NumOpenPulls = repo.NumPulls - repo.NumClosedPulls
- case "num_closed_milestones":
- repo.NumOpenMilestones = repo.NumMilestones - repo.NumClosedMilestones
- case "created_unix":
- repo.Created = time.Unix(repo.CreatedUnix, 0).Local()
- case "updated_unix":
- repo.Updated = time.Unix(repo.UpdatedUnix, 0)
- }
+// AfterLoad is invoked from XORM after setting the values of all fields of this object.
+func (repo *Repository) AfterLoad() {
+ // FIXME: use models migration to solve all at once.
+ if len(repo.DefaultBranch) == 0 {
+ repo.DefaultBranch = "master"
+ }
+
+ repo.NumOpenIssues = repo.NumIssues - repo.NumClosedIssues
+ repo.NumOpenPulls = repo.NumPulls - repo.NumClosedPulls
+ repo.NumOpenMilestones = repo.NumMilestones - repo.NumClosedMilestones
+ repo.Created = time.Unix(repo.CreatedUnix, 0).Local()
+ repo.Updated = time.Unix(repo.UpdatedUnix, 0)
}
// MustOwner always returns a valid *User object to avoid