Browse Source

models: skip JSON for fields skipped by XORM

Reduce output JSON size by backup command
Unknwon 6 years ago
parent
commit
53c8e4263b

+ 2 - 2
models/action.go

@@ -80,14 +80,14 @@ type Action struct {
 	OpType       ActionType
 	ActUserID    int64  // Doer user ID
 	ActUserName  string // Doer user name
-	ActAvatar    string `xorm:"-"`
+	ActAvatar    string `xorm:"-" json:"-"`
 	RepoID       int64  `xorm:"INDEX"`
 	RepoUserName string
 	RepoName     string
 	RefName      string
 	IsPrivate    bool      `xorm:"NOT NULL DEFAULT false"`
 	Content      string    `xorm:"TEXT"`
-	Created      time.Time `xorm:"-"`
+	Created      time.Time `xorm:"-" json:"-"`
 	CreatedUnix  int64
 }
 

+ 1 - 1
models/admin.go

@@ -30,7 +30,7 @@ type Notice struct {
 	ID          int64
 	Type        NoticeType
 	Description string    `xorm:"TEXT"`
-	Created     time.Time `xorm:"-"`
+	Created     time.Time `xorm:"-" json:"-"`
 	CreatedUnix int64
 }
 

+ 1 - 1
models/attachment.go

@@ -27,7 +27,7 @@ type Attachment struct {
 	ReleaseID int64 `xorm:"INDEX"`
 	Name      string
 
-	Created     time.Time `xorm:"-"`
+	Created     time.Time `xorm:"-" json:"-"`
 	CreatedUnix int64
 }
 

+ 7 - 7
models/comment.go

@@ -52,26 +52,26 @@ type Comment struct {
 	ID              int64
 	Type            CommentType
 	PosterID        int64
-	Poster          *User  `xorm:"-"`
+	Poster          *User  `xorm:"-" json:"-"`
 	IssueID         int64  `xorm:"INDEX"`
-	Issue           *Issue `xorm:"-"`
+	Issue           *Issue `xorm:"-" json:"-"`
 	CommitID        int64
 	Line            int64
 	Content         string `xorm:"TEXT"`
-	RenderedContent string `xorm:"-"`
+	RenderedContent string `xorm:"-" json:"-"`
 
-	Created     time.Time `xorm:"-"`
+	Created     time.Time `xorm:"-" json:"-"`
 	CreatedUnix int64
-	Updated     time.Time `xorm:"-"`
+	Updated     time.Time `xorm:"-" json:"-"`
 	UpdatedUnix int64
 
 	// Reference issue in commit message
 	CommitSHA string `xorm:"VARCHAR(40)"`
 
-	Attachments []*Attachment `xorm:"-"`
+	Attachments []*Attachment `xorm:"-" json:"-"`
 
 	// For view issue page.
-	ShowTag CommentTag `xorm:"-"`
+	ShowTag CommentTag `xorm:"-" json:"-"`
 }
 
 func (c *Comment) BeforeInsert() {

+ 13 - 13
models/issue.go

@@ -28,34 +28,34 @@ var (
 type Issue struct {
 	ID              int64
 	RepoID          int64       `xorm:"INDEX UNIQUE(repo_index)"`
-	Repo            *Repository `xorm:"-"`
+	Repo            *Repository `xorm:"-" json:"-"`
 	Index           int64       `xorm:"UNIQUE(repo_index)"` // Index in one repository.
 	PosterID        int64
-	Poster          *User    `xorm:"-"`
+	Poster          *User    `xorm:"-" json:"-"`
 	Title           string   `xorm:"name"`
 	Content         string   `xorm:"TEXT"`
-	RenderedContent string   `xorm:"-"`
-	Labels          []*Label `xorm:"-"`
+	RenderedContent string   `xorm:"-" json:"-"`
+	Labels          []*Label `xorm:"-" json:"-"`
 	MilestoneID     int64
-	Milestone       *Milestone `xorm:"-"`
+	Milestone       *Milestone `xorm:"-" json:"-"`
 	Priority        int
 	AssigneeID      int64
-	Assignee        *User `xorm:"-"`
+	Assignee        *User `xorm:"-" json:"-"`
 	IsClosed        bool
-	IsRead          bool         `xorm:"-"`
+	IsRead          bool         `xorm:"-" json:"-"`
 	IsPull          bool         // Indicates whether is a pull request or not.
-	PullRequest     *PullRequest `xorm:"-"`
+	PullRequest     *PullRequest `xorm:"-" json:"-"`
 	NumComments     int
 
-	Deadline     time.Time `xorm:"-"`
+	Deadline     time.Time `xorm:"-" json:"-"`
 	DeadlineUnix int64
-	Created      time.Time `xorm:"-"`
+	Created      time.Time `xorm:"-" json:"-"`
 	CreatedUnix  int64
-	Updated      time.Time `xorm:"-"`
+	Updated      time.Time `xorm:"-" json:"-"`
 	UpdatedUnix  int64
 
-	Attachments []*Attachment `xorm:"-"`
-	Comments    []*Comment    `xorm:"-"`
+	Attachments []*Attachment `xorm:"-" json:"-"`
+	Comments    []*Comment    `xorm:"-" json:"-"`
 }
 
 func (issue *Issue) BeforeInsert() {

+ 2 - 2
models/issue_label.go

@@ -60,8 +60,8 @@ type Label struct {
 	Color           string `xorm:"VARCHAR(7)"`
 	NumIssues       int
 	NumClosedIssues int
-	NumOpenIssues   int  `xorm:"-"`
-	IsChecked       bool `xorm:"-"`
+	NumOpenIssues   int  `xorm:"-" json:"-"`
+	IsChecked       bool `xorm:"-" json:"-"`
 }
 
 func (label *Label) APIFormat() *api.Label {

+ 3 - 3
models/login_source.go

@@ -135,12 +135,12 @@ type LoginSource struct {
 	IsActived bool            `xorm:"NOT NULL DEFAULT false"`
 	Cfg       core.Conversion `xorm:"TEXT"`
 
-	Created     time.Time `xorm:"-"`
+	Created     time.Time `xorm:"-" json:"-"`
 	CreatedUnix int64
-	Updated     time.Time `xorm:"-"`
+	Updated     time.Time `xorm:"-" json:"-"`
 	UpdatedUnix int64
 
-	LocalFile *AuthSourceFile `xorm:"-"`
+	LocalFile *AuthSourceFile `xorm:"-" json:"-"`
 }
 
 func (s *LoginSource) BeforeInsert() {

+ 6 - 6
models/milestone.go

@@ -22,18 +22,18 @@ type Milestone struct {
 	RepoID          int64 `xorm:"INDEX"`
 	Name            string
 	Content         string `xorm:"TEXT"`
-	RenderedContent string `xorm:"-"`
+	RenderedContent string `xorm:"-" json:"-"`
 	IsClosed        bool
 	NumIssues       int
 	NumClosedIssues int
-	NumOpenIssues   int  `xorm:"-"`
+	NumOpenIssues   int  `xorm:"-" json:"-"`
 	Completeness    int  // Percentage(1-100).
-	IsOverDue       bool `xorm:"-"`
+	IsOverDue       bool `xorm:"-" json:"-"`
 
-	DeadlineString string    `xorm:"-"`
-	Deadline       time.Time `xorm:"-"`
+	DeadlineString string    `xorm:"-" json:"-"`
+	Deadline       time.Time `xorm:"-" json:"-"`
 	DeadlineUnix   int64
-	ClosedDate     time.Time `xorm:"-"`
+	ClosedDate     time.Time `xorm:"-" json:"-"`
 	ClosedDateUnix int64
 }
 

+ 4 - 4
models/mirror.go

@@ -29,17 +29,17 @@ var MirrorQueue = sync.NewUniqueQueue(setting.Repository.MirrorQueueLength)
 type Mirror struct {
 	ID          int64
 	RepoID      int64
-	Repo        *Repository `xorm:"-"`
+	Repo        *Repository `xorm:"-" json:"-"`
 	Interval    int         // Hour.
 	EnablePrune bool        `xorm:"NOT NULL DEFAULT true"`
 
 	// Last and next sync time of Git data from upstream
-	LastSync     time.Time `xorm:"-"`
+	LastSync     time.Time `xorm:"-" json:"-"`
 	LastSyncUnix int64     `xorm:"updated_unix"`
-	NextSync     time.Time `xorm:"-"`
+	NextSync     time.Time `xorm:"-" json:"-"`
 	NextSyncUnix int64     `xorm:"next_update_unix"`
 
-	address string `xorm:"-"`
+	address string `xorm:"-" json:"-"`
 }
 
 func (m *Mirror) BeforeInsert() {

+ 2 - 2
models/org_team.go

@@ -22,8 +22,8 @@ type Team struct {
 	Name        string
 	Description string
 	Authorize   AccessMode
-	Repos       []*Repository `xorm:"-"`
-	Members     []*User       `xorm:"-"`
+	Repos       []*Repository `xorm:"-" json:"-"`
+	Members     []*User       `xorm:"-" json:"-"`
 	NumRepos    int
 	NumMembers  int
 }

+ 5 - 5
models/pull.go

@@ -48,13 +48,13 @@ type PullRequest struct {
 	Status PullRequestStatus
 
 	IssueID int64  `xorm:"INDEX"`
-	Issue   *Issue `xorm:"-"`
+	Issue   *Issue `xorm:"-" json:"-"`
 	Index   int64
 
 	HeadRepoID   int64
-	HeadRepo     *Repository `xorm:"-"`
+	HeadRepo     *Repository `xorm:"-" json:"-"`
 	BaseRepoID   int64
-	BaseRepo     *Repository `xorm:"-"`
+	BaseRepo     *Repository `xorm:"-" json:"-"`
 	HeadUserName string
 	HeadBranch   string
 	BaseBranch   string
@@ -63,8 +63,8 @@ type PullRequest struct {
 	HasMerged      bool
 	MergedCommitID string `xorm:"VARCHAR(40)"`
 	MergerID       int64
-	Merger         *User     `xorm:"-"`
-	Merged         time.Time `xorm:"-"`
+	Merger         *User     `xorm:"-" json:"-"`
+	Merged         time.Time `xorm:"-" json:"-"`
 	MergedUnix     int64
 }
 

+ 5 - 5
models/release.go

@@ -24,24 +24,24 @@ import (
 type Release struct {
 	ID               int64
 	RepoID           int64
-	Repo             *Repository `xorm:"-"`
+	Repo             *Repository `xorm:"-" json:"-"`
 	PublisherID      int64
-	Publisher        *User `xorm:"-"`
+	Publisher        *User `xorm:"-" json:"-"`
 	TagName          string
 	LowerTagName     string
 	Target           string
 	Title            string
 	Sha1             string `xorm:"VARCHAR(40)"`
 	NumCommits       int64
-	NumCommitsBehind int64  `xorm:"-"`
+	NumCommitsBehind int64  `xorm:"-" json:"-"`
 	Note             string `xorm:"TEXT"`
 	IsDraft          bool   `xorm:"NOT NULL DEFAULT false"`
 	IsPrerelease     bool
 
-	Created     time.Time `xorm:"-"`
+	Created     time.Time `xorm:"-" json:"-"`
 	CreatedUnix int64
 
-	Attachments []*Attachment `xorm:"-"`
+	Attachments []*Attachment `xorm:"-" json:"-"`
 }
 
 func (r *Release) BeforeInsert() {

+ 10 - 10
models/repo.go

@@ -143,7 +143,7 @@ func NewRepoContext() {
 type Repository struct {
 	ID            int64
 	OwnerID       int64  `xorm:"UNIQUE(s)"`
-	Owner         *User  `xorm:"-"`
+	Owner         *User  `xorm:"-" json:"-"`
 	LowerName     string `xorm:"UNIQUE(s) INDEX NOT NULL"`
 	Name          string `xorm:"INDEX NOT NULL"`
 	Description   string
@@ -156,20 +156,20 @@ type Repository struct {
 	NumForks            int
 	NumIssues           int
 	NumClosedIssues     int
-	NumOpenIssues       int `xorm:"-"`
+	NumOpenIssues       int `xorm:"-" json:"-"`
 	NumPulls            int
 	NumClosedPulls      int
-	NumOpenPulls        int `xorm:"-"`
+	NumOpenPulls        int `xorm:"-" json:"-"`
 	NumMilestones       int `xorm:"NOT NULL DEFAULT 0"`
 	NumClosedMilestones int `xorm:"NOT NULL DEFAULT 0"`
-	NumOpenMilestones   int `xorm:"-"`
-	NumTags             int `xorm:"-"`
+	NumOpenMilestones   int `xorm:"-" json:"-"`
+	NumTags             int `xorm:"-" json:"-"`
 
 	IsPrivate bool
 	IsBare    bool
 
 	IsMirror bool
-	*Mirror  `xorm:"-"`
+	*Mirror  `xorm:"-" json:"-"`
 
 	// Advanced settings
 	EnableWiki            bool `xorm:"NOT NULL DEFAULT true"`
@@ -182,18 +182,18 @@ type Repository struct {
 	ExternalTrackerURL    string
 	ExternalTrackerFormat string
 	ExternalTrackerStyle  string
-	ExternalMetas         map[string]string `xorm:"-"`
+	ExternalMetas         map[string]string `xorm:"-" json:"-"`
 	EnablePulls           bool              `xorm:"NOT NULL DEFAULT true"`
 	PullsIgnoreWhitespace bool              `xorm:"NOT NULL DEFAULT false"`
 	PullsAllowRebase      bool              `xorm:"NOT NULL DEFAULT false"`
 
 	IsFork   bool `xorm:"NOT NULL DEFAULT false"`
 	ForkID   int64
-	BaseRepo *Repository `xorm:"-"`
+	BaseRepo *Repository `xorm:"-" json:"-"`
 
-	Created     time.Time `xorm:"-"`
+	Created     time.Time `xorm:"-" json:"-"`
 	CreatedUnix int64
-	Updated     time.Time `xorm:"-"`
+	Updated     time.Time `xorm:"-" json:"-"`
 	UpdatedUnix int64
 }
 

+ 9 - 9
models/ssh_key.go

@@ -51,12 +51,12 @@ type PublicKey struct {
 	Mode        AccessMode `xorm:"NOT NULL DEFAULT 2"`
 	Type        KeyType    `xorm:"NOT NULL DEFAULT 1"`
 
-	Created           time.Time `xorm:"-"`
+	Created           time.Time `xorm:"-" json:"-"`
 	CreatedUnix       int64
-	Updated           time.Time `xorm:"-"` // Note: Updated must below Created for AfterSet.
+	Updated           time.Time `xorm:"-" json:"-"` // Note: Updated must below Created for AfterSet.
 	UpdatedUnix       int64
-	HasRecentActivity bool `xorm:"-"`
-	HasUsed           bool `xorm:"-"`
+	HasRecentActivity bool `xorm:"-" json:"-"`
+	HasUsed           bool `xorm:"-" json:"-"`
 }
 
 func (k *PublicKey) BeforeInsert() {
@@ -568,14 +568,14 @@ type DeployKey struct {
 	RepoID      int64 `xorm:"UNIQUE(s) INDEX"`
 	Name        string
 	Fingerprint string
-	Content     string `xorm:"-"`
+	Content     string `xorm:"-" json:"-"`
 
-	Created           time.Time `xorm:"-"`
+	Created           time.Time `xorm:"-" json:"-"`
 	CreatedUnix       int64
-	Updated           time.Time `xorm:"-"` // Note: Updated must below Created for AfterSet.
+	Updated           time.Time `xorm:"-" json:"-"` // Note: Updated must below Created for AfterSet.
 	UpdatedUnix       int64
-	HasRecentActivity bool `xorm:"-"`
-	HasUsed           bool `xorm:"-"`
+	HasRecentActivity bool `xorm:"-" json:"-"`
+	HasUsed           bool `xorm:"-" json:"-"`
 }
 
 func (k *DeployKey) BeforeInsert() {

+ 4 - 4
models/token.go

@@ -20,12 +20,12 @@ type AccessToken struct {
 	Name string
 	Sha1 string `xorm:"UNIQUE VARCHAR(40)"`
 
-	Created           time.Time `xorm:"-"`
+	Created           time.Time `xorm:"-" json:"-"`
 	CreatedUnix       int64
-	Updated           time.Time `xorm:"-"` // Note: Updated must below Created for AfterSet.
+	Updated           time.Time `xorm:"-" json:"-"` // Note: Updated must below Created for AfterSet.
 	UpdatedUnix       int64
-	HasRecentActivity bool `xorm:"-"`
-	HasUsed           bool `xorm:"-"`
+	HasRecentActivity bool `xorm:"-" json:"-"`
+	HasUsed           bool `xorm:"-" json:"-"`
 }
 
 func (t *AccessToken) BeforeInsert() {

+ 1 - 1
models/two_factor.go

@@ -25,7 +25,7 @@ type TwoFactor struct {
 	ID          int64
 	UserID      int64 `xorm:"UNIQUE"`
 	Secret      string
-	Created     time.Time `xorm:"-"`
+	Created     time.Time `xorm:"-" json:"-"`
 	CreatedUnix int64
 }
 

+ 7 - 7
models/user.go

@@ -55,17 +55,17 @@ type User struct {
 	LoginSource int64 `xorm:"NOT NULL DEFAULT 0"`
 	LoginName   string
 	Type        UserType
-	OwnedOrgs   []*User       `xorm:"-"`
-	Orgs        []*User       `xorm:"-"`
-	Repos       []*Repository `xorm:"-"`
+	OwnedOrgs   []*User       `xorm:"-" json:"-"`
+	Orgs        []*User       `xorm:"-" json:"-"`
+	Repos       []*Repository `xorm:"-" json:"-"`
 	Location    string
 	Website     string
 	Rands       string `xorm:"VARCHAR(10)"`
 	Salt        string `xorm:"VARCHAR(10)"`
 
-	Created     time.Time `xorm:"-"`
+	Created     time.Time `xorm:"-" json:"-"`
 	CreatedUnix int64
-	Updated     time.Time `xorm:"-"`
+	Updated     time.Time `xorm:"-" json:"-"`
 	UpdatedUnix int64
 
 	// Remember visibility choice for convenience, true for private
@@ -95,8 +95,8 @@ type User struct {
 	Description string
 	NumTeams    int
 	NumMembers  int
-	Teams       []*Team `xorm:"-"`
-	Members     []*User `xorm:"-"`
+	Teams       []*Team `xorm:"-" json:"-"`
+	Members     []*User `xorm:"-" json:"-"`
 }
 
 func (u *User) BeforeInsert() {

+ 1 - 1
models/user_mail.go

@@ -18,7 +18,7 @@ type EmailAddress struct {
 	UID         int64  `xorm:"INDEX NOT NULL"`
 	Email       string `xorm:"UNIQUE NOT NULL"`
 	IsActivated bool
-	IsPrimary   bool `xorm:"-"`
+	IsPrimary   bool `xorm:"-" json:"-"`
 }
 
 // GetEmailAddresses returns all email addresses belongs to given user.

+ 7 - 7
models/webhook.go

@@ -99,16 +99,16 @@ type Webhook struct {
 	ContentType  HookContentType
 	Secret       string `xorm:"TEXT"`
 	Events       string `xorm:"TEXT"`
-	*HookEvent   `xorm:"-"`
+	*HookEvent   `xorm:"-" json:"-"`
 	IsSSL        bool `xorm:"is_ssl"`
 	IsActive     bool
 	HookTaskType HookTaskType
 	Meta         string     `xorm:"TEXT"` // store hook-specific attributes
 	LastStatus   HookStatus // Last delivery status
 
-	Created     time.Time `xorm:"-"`
+	Created     time.Time `xorm:"-" json:"-"`
 	CreatedUnix int64
-	Updated     time.Time `xorm:"-"`
+	Updated     time.Time `xorm:"-" json:"-"`
 	UpdatedUnix int64
 }
 
@@ -418,21 +418,21 @@ type HookTask struct {
 	Type            HookTaskType
 	URL             string `xorm:"TEXT"`
 	Signature       string `xorm:"TEXT"`
-	api.Payloader   `xorm:"-"`
+	api.Payloader   `xorm:"-" json:"-"`
 	PayloadContent  string `xorm:"TEXT"`
 	ContentType     HookContentType
 	EventType       HookEventType
 	IsSSL           bool
 	IsDelivered     bool
 	Delivered       int64
-	DeliveredString string `xorm:"-"`
+	DeliveredString string `xorm:"-" json:"-"`
 
 	// History info.
 	IsSucceed       bool
 	RequestContent  string        `xorm:"TEXT"`
-	RequestInfo     *HookRequest  `xorm:"-"`
+	RequestInfo     *HookRequest  `xorm:"-" json:"-"`
 	ResponseContent string        `xorm:"TEXT"`
-	ResponseInfo    *HookResponse `xorm:"-"`
+	ResponseInfo    *HookResponse `xorm:"-" json:"-"`
 }
 
 func (t *HookTask) BeforeUpdate() {