Exemplo n.º 1
3
func RefreshStats(cache *Cache, db *gorm.DB) (err error) {
	m := &runtime.MemStats{}
	runtime.ReadMemStats(m)

	acq := m.Sys / 1024 / 1024
	used := m.Alloc / 1024 / 1024

	m = nil

	stats.GoRoutines = runtime.NumGoroutine()
	stats.MemoryAcq = int(acq)
	stats.MemoryUsed = int(used)

	stats.CacheMB = cache.GetSizeInMb()
	stats.CacheCount = cache.GetSize()

	stats.Rel = nil
	stats.Ta = nil

	err = db.Order("weight desc").Limit(10).Find(&stats.Ta).Error
	if err != nil {
		return
	}

	err = db.Order("hits desc").Limit(10).Find(&stats.Rel).Error
	if err != nil {
		return
	}

	row := db.Raw(HITCOUNT).Row()
	row.Scan(&stats.HitCount)

	row = db.Raw(TAGCOUNT).Row()
	row.Scan(&stats.TagCount)

	row = db.Raw(RELEASECOUNT).Row()
	row.Scan(&stats.ReleaseCount)

	return
}
Exemplo n.º 2
1
func getUniqueMapsCount(db *gorm.DB) uint {
	var result = struct {
		Maps uint
	}{}
	db.Raw("select count(map) as maps from (select distinct map from matches)").
		Scan(&result)
	log.Printf("unique maps: %u", result.Maps)
	return result.Maps
}
Exemplo n.º 3
1
// ReleasesLastVersion returns the last ReleaseVersion for the given App. This
// function also ensures that the last release is locked until the transaction
// is commited, so the release version can be incremented atomically.
func releasesLastVersion(db *gorm.DB, appID string) (int, error) {
	var version int

	rows, err := db.Raw(`select version from releases where app_id = ? order by version desc for update`, appID).Rows()
	if err != nil {
		return version, err
	}
	defer rows.Close()

	for rows.Next() {
		err := rows.Scan(&version)
		return version, err
	}

	return version, nil
}
Exemplo n.º 4
1
func getColumnNames(db gorm.DB, table string) [][]string {
	query := `select column_name, data_type from information_schema.columns 
              where table_name = '` + table + `'`
	rows, err := db.Raw(query).Rows()
	if err != nil {
		panic(err)
	}
	defer rows.Close()

	var rowData [][]string
	for rows.Next() {
		var columnName string
		var dataType string

		rows.Scan(&columnName, &dataType)
		rowData = append(rowData, []string{columnName, dataType})
	}
	return rowData
}