summaryrefslogtreecommitdiffstats
path: root/models/notification.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2017-12-11 12:37:04 +0800
committerLauris BH <lauris@nix.lv>2017-12-11 06:37:04 +0200
commitf2e20c81b66e6a937ecdb686f8d1011371433365 (patch)
tree490e5af82aefdd25de5d90225b083ecb3ed11e5f /models/notification.go
parentc082c3bce35d6d5d829a1e516b9bbf45b6d49bdc (diff)
downloadgitea-f2e20c81b66e6a937ecdb686f8d1011371433365.tar.gz
gitea-f2e20c81b66e6a937ecdb686f8d1011371433365.zip
Refactor struct's time to remove unnecessary memory usage (#3142)
* refactor struct's time to remove unnecessary memory usage * use AsTimePtr simple code * fix tests * fix time compare * fix template on gpg * use AddDuration instead of Add
Diffstat (limited to 'models/notification.go')
-rw-r--r--models/notification.go32
1 files changed, 5 insertions, 27 deletions
diff --git a/models/notification.go b/models/notification.go
index dcd624e514..c8376a857b 100644
--- a/models/notification.go
+++ b/models/notification.go
@@ -6,7 +6,8 @@ package models
import (
"fmt"
- "time"
+
+ "code.gitea.io/gitea/modules/util"
)
type (
@@ -51,32 +52,8 @@ type Notification struct {
Issue *Issue `xorm:"-"`
Repository *Repository `xorm:"-"`
- Created time.Time `xorm:"-"`
- CreatedUnix int64 `xorm:"INDEX NOT NULL"`
- Updated time.Time `xorm:"-"`
- UpdatedUnix int64 `xorm:"INDEX NOT NULL"`
-}
-
-// BeforeInsert runs while inserting a record
-func (n *Notification) BeforeInsert() {
- var (
- now = time.Now()
- nowUnix = now.Unix()
- )
- n.Created = now
- n.CreatedUnix = nowUnix
- n.Updated = now
- n.UpdatedUnix = nowUnix
-}
-
-// BeforeUpdate runs while updating a record
-func (n *Notification) BeforeUpdate() {
- var (
- now = time.Now()
- nowUnix = now.Unix()
- )
- n.Updated = now
- n.UpdatedUnix = nowUnix
+ CreatedUnix util.TimeStamp `xorm:"created INDEX NOT NULL"`
+ UpdatedUnix util.TimeStamp `xorm:"updated INDEX NOT NULL"`
}
// CreateOrUpdateIssueNotifications creates an issue notification
@@ -212,6 +189,7 @@ func getIssueNotification(e Engine, userID, issueID int64) (*Notification, error
func NotificationsForUser(user *User, statuses []NotificationStatus, page, perPage int) ([]*Notification, error) {
return notificationsForUser(x, user, statuses, page, perPage)
}
+
func notificationsForUser(e Engine, user *User, statuses []NotificationStatus, page, perPage int) (notifications []*Notification, err error) {
if len(statuses) == 0 {
return