<commit_before>// Copyright 2016 The Gogs Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package models

import (
	"fmt"
	"strings"
	"time"

	"github.com/Unknwon/com"
	"github.com/go-xorm/xorm"
	log "gopkg.in/clog.v1"
	"gopkg.in/ini.v1"

	"github.com/gogits/git-module"

	"github.com/gogits/gogs/models/errors"
	"github.com/gogits/gogs/modules/process"
	"github.com/gogits/gogs/modules/setting"
	"github.com/gogits/gogs/modules/sync"
)

var MirrorQueue = sync.NewUniqueQueue(setting.Repository.MirrorQueueLength)

// Mirror represents mirror information of a repository.
type Mirror struct {
	ID          int64 `xorm:"pk autoincr"`
	RepoID      int64
	Repo        *Repository `xorm:"-"`
	Interval    int         // Hour.
	EnablePrune bool        `xorm:"NOT NULL DEFAULT true"`

	Updated        time.Time `xorm:"-"`
	UpdatedUnix    int64
	NextUpdate     time.Time `xorm:"-"`
	NextUpdateUnix int64

	address string `xorm:"-"`
}

func (m *Mirror) BeforeInsert() {
	m.UpdatedUnix = time.Now().Unix()
	m.NextUpdateUnix = m.NextUpdate.Unix()
}

func (m *Mirror) BeforeUpdate() {
	m.UpdatedUnix = time.Now().Unix()
	m.NextUpdateUnix = m.NextUpdate.Unix()
}

func (m *Mirror) AfterSet(colName string, _ xorm.Cell) {
	var err error
	switch colName {
	case "repo_id":
		m.Repo, err = GetRepositoryByID(m.RepoID)
		if err != nil {
			log.Error(3, "GetRepositoryByID [%d]: %v", m.ID, err)
		}
	case "updated_unix":
		m.Updated = time.Unix(m.UpdatedUnix, 0).Local()
	case "next_updated_unix":
		m.NextUpdate = time.Unix(m.NextUpdateUnix, 0).Local()
	}
}

// ScheduleNextUpdate calculates and sets next update time.
func (m *Mirror) ScheduleNextUpdate() {
	m.NextUpdate = time.Now().Add(time.Duration(m.Interval) * time.Hour)
}

func (m *Mirror) readAddress() {
	if len(m.address) > 0 {
		return
	}
<commit_msg>modes/mirror: corrected NextUpdate not set (#4345)<commit_after>// Copyright 2016 The Gogs Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package models

import (
	"fmt"
	"strings"
	"time"

	"github.com/Unknwon/com"
	"github.com/go-xorm/xorm"
	log "gopkg.in/clog.v1"
	"gopkg.in/ini.v1"

	"github.com/gogits/git-module"

	"github.com/gogits/gogs/models/errors"
	"github.com/gogits/gogs/modules/process"
	"github.com/gogits/gogs/modules/setting"
	"github.com/gogits/gogs/modules/sync"
)

var MirrorQueue = sync.NewUniqueQueue(setting.Repository.MirrorQueueLength)

// Mirror represents mirror information of a repository.
type Mirror struct {
	ID          int64 `xorm:"pk autoincr"`
	RepoID      int64
	Repo        *Repository `xorm:"-"`
	Interval    int         // Hour.
	EnablePrune bool        `xorm:"NOT NULL DEFAULT true"`

	Updated        time.Time `xorm:"-"`
	UpdatedUnix    int64
	NextUpdate     time.Time `xorm:"-"`
	NextUpdateUnix int64

	address string `xorm:"-"`
}

func (m *Mirror) BeforeInsert() {
	m.UpdatedUnix = time.Now().Unix()
	m.NextUpdateUnix = m.NextUpdate.Unix()
}

func (m *Mirror) BeforeUpdate() {
	m.UpdatedUnix = time.Now().Unix()
	m.NextUpdateUnix = m.NextUpdate.Unix()
}

func (m *Mirror) AfterSet(colName string, _ xorm.Cell) {
	var err error
	switch colName {
	case "repo_id":
		m.Repo, err = GetRepositoryByID(m.RepoID)
		if err != nil {
			log.Error(3, "GetRepositoryByID [%d]: %v", m.ID, err)
		}
	case "updated_unix":
		m.Updated = time.Unix(m.UpdatedUnix, 0).Local()
	case "next_update_unix":
		m.NextUpdate = time.Unix(m.NextUpdateUnix, 0).Local()
	}
}

// ScheduleNextUpdate calculates and sets next update time.
func (m *Mirror) ScheduleNextUpdate() {
	m.NextUpdate = time.Now().Add(time.Duration(m.Interval) * time.Hour)
}

func (m *Mirror) readAddress() {
	if len(m.address) > 0 {
		return
	}

{'fraction_non_alphanumeric': 0.14266946925906462, 'fraction_numerical': 0.010509721492380452, 'mean_word_length': 3.5812274368231045, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1019184', 'n_tokens_mistral': 1502, 'n_tokens_neox': 1434, 'n_words': 327}