Skip to content

Commit

Permalink
Optimize indices for large tables
Browse files Browse the repository at this point in the history
Adding an index on instance_id and created_at will allow
the dataset to be ordered and filtered a lot faster, especially
when there are a lot of orders.
Also, since the custom names for indices are removed, indices will
now be properly prefixed.
  • Loading branch information
mraerino committed Jan 29, 2019
1 parent d717211 commit e713513
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion models/download.go
Expand Up @@ -22,7 +22,7 @@ type Download struct {


CreatedAt time.Time `json:"created_at"` CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"` UpdatedAt time.Time `json:"updated_at"`
DeletedAt *time.Time `json:"-" sql:"index:idx_downloads_deleted_at"` DeletedAt *time.Time `json:"-" sql:"index"`
} }


// TableName returns the database table name for the Download model. // TableName returns the database table name for the Download model.
Expand Down
6 changes: 3 additions & 3 deletions models/order.go
Expand Up @@ -50,7 +50,7 @@ const (


// Order model // Order model
type Order struct { type Order struct {
InstanceID string `json:"-"` InstanceID string `json:"-" sql:"index"`
ID string `json:"id"` ID string `json:"id"`
InvoiceNumber int64 `json:"invoice_number,omitempty"` InvoiceNumber int64 `json:"invoice_number,omitempty"`


Expand Down Expand Up @@ -100,9 +100,9 @@ type Order struct {
Coupon *Coupon `json:"coupon,omitempty" sql:"-"` Coupon *Coupon `json:"coupon,omitempty" sql:"-"`
RawCoupon string `json:"-" sql:"type:text"` RawCoupon string `json:"-" sql:"type:text"`


CreatedAt time.Time `json:"created_at"` CreatedAt time.Time `json:"created_at" sql:"index"`
UpdatedAt time.Time `json:"updated_at"` UpdatedAt time.Time `json:"updated_at"`
DeletedAt *time.Time `json:"-" sql:"index:idx_orders_deleted_at"` DeletedAt *time.Time `json:"-" sql:"index"`
} }


// TableName returns the database table name for the Order model. // TableName returns the database table name for the Order model.
Expand Down

0 comments on commit e713513

Please sign in to comment.