<commit_before>package torrents

import (
	"errors"
	"net/http"
	"strconv"
	"strings"

	"time"

	"github.com/NyaaPantsu/nyaa/config"
	"github.com/NyaaPantsu/nyaa/models"
	"github.com/NyaaPantsu/nyaa/utils/cache"
	"github.com/NyaaPantsu/nyaa/utils/search/structs"
)

/* Function to interact with Models
 *
 * Get the torrents with where clause
 *
 */

// FindByID : get a torrent with its id
func FindByID(id uint) (*models.Torrent, error) {
	torrent := &models.Torrent{ID: id}
	var err error
	if found, ok := cache.C.Get(torrent.Identifier()); ok {
		return found.(*models.Torrent), nil
	}
	torrent = &models.Torrent{}
	tmp := models.ORM.Where("torrent_id = ?", id).Preload("Scrape").Preload("Comments")
	if id > config.Conf.Models.LastOldTorrentID {
		tmp = tmp.Preload("FileList")
	}
	if id <= config.Conf.Models.LastOldTorrentID && !config.IsSukebei() {
		// only preload old comments if they could actually exist
		tmp = tmp.Preload("OldComments")
	}
	err = tmp.Error
	if err != nil {
		return torrent, err
	}
	if tmp.Find(torrent).RecordNotFound() {
		err = errors.New("Article is not found")
		return torrent, err
	}
	torrent.ParseLanguages()
	// GORM relly likes not doing its job correctly
	// (or maybe I'm just retarded)
	torrent.OldUploader = ""
	if torrent.ID <= config.Conf.Models.LastOldTorrentID && torrent.UploaderID == 0 {
		var tmp models.UserUploadsOld
		if !models.ORM.Where("torrent_id = ?", torrent.ID).Find(&tmp).RecordNotFound() {
			torrent.OldUploader = tmp.Username<commit_msg>Fix for edit modpanel<commit_after>package torrents

import (
	"errors"
	"net/http"
	"strconv"
	"strings"

	"time"

	"github.com/NyaaPantsu/nyaa/config"
	"github.com/NyaaPantsu/nyaa/models"
	"github.com/NyaaPantsu/nyaa/utils/cache"
	"github.com/NyaaPantsu/nyaa/utils/search/structs"
)

/* Function to interact with Models
 *
 * Get the torrents with where clause
 *
 */

// FindByID : get a torrent with its id
func FindByID(id uint) (*models.Torrent, error) {
	torrent := &models.Torrent{ID: id}
	var err error
	if found, ok := cache.C.Get(torrent.Identifier()); ok {
		return found.(*models.Torrent), nil
	}
	torrent = &models.Torrent{}
	tmp := models.ORM.Where("torrent_id = ?", id).Preload("Scrape").Preload("Uploader").Preload("Comments")
	if id > config.Conf.Models.LastOldTorrentID {
		tmp = tmp.Preload("FileList")
	}
	if id <= config.Conf.Models.LastOldTorrentID && !config.IsSukebei() {
		// only preload old comments if they could actually exist
		tmp = tmp.Preload("OldComments")
	}
	err = tmp.Error
	if err != nil {
		return torrent, err
	}
	if tmp.Find(torrent).RecordNotFound() {
		err = errors.New("Article is not found")
		return torrent, err
	}
	torrent.ParseLanguages()
	// GORM relly likes not doing its job correctly
	// (or maybe I'm just retarded)
	torrent.OldUploader = ""
	if torrent.ID <= config.Conf.Models.LastOldTorrentID && torrent.UploaderID == 0 {
		var tmp models.UserUploadsOld
		if !models.ORM.Where("torrent_id = ?", torrent.ID).Find(&tmp).RecordNotFound() {
			torrent.OldUploader = tmp.Username
{'fraction_non_alphanumeric': 0.14459815546772067, 'fraction_numerical': 0.0006587615283267457, 'mean_word_length': 4.1042016806722685, 'pattern_counts': {'":': 0, '<': 7, '<?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': '1424580', 'n_tokens_mistral': 1159, 'n_tokens_neox': 1100, 'n_words': 242}