<commit_before>package pixur

import (
	"database/sql"
	"fmt"
	"strings"
)

type ReadIndexPicsTask struct {
	// Deps
	db *sql.DB

	// Inputs

	// State

	// Results
	Pics []*Pic
}

func (t *ReadIndexPicsTask) Reset() {}

func (t *ReadIndexPicsTask) Run() TaskError {
	var columnNameMap = (&Pic{}).PointerMap()

	var columnNames = make([]string, 0, len(columnNameMap))
	for name, _ := range columnNameMap {
		columnNames = append(columnNames, name)
	}

	stmt := fmt.Sprintf("SELECT %s FROM pix;", strings.Join(columnNames, ","))
	rows, err := t.db.Query(stmt)
	if err != nil {
		return err
	}
	defer rows.Close()

	var pics []*Pic
	for rows.Next() {
		var p = new(Pic)
		pmap := p.PointerMap()

		var rawRowValues = make([]interface{}, 0, len(columnNames))
		for _, columnName := range columnNames {
			rawRowValues = append(rawRowValues, pmap[columnName])
		}
		if err := rows.Scan(rawRowValues...); err != nil {
			return err
		}
		pics = append(pics, p)
	}

	if err := rows.Err(); err != nil {
		return err
	}

	t.Pics = pics
<commit_msg>Changed sort order on index page<commit_after>package pixur

import (
	"database/sql"
	"fmt"
	"strings"
)

type ReadIndexPicsTask struct {
	// Deps
	db *sql.DB

	// Inputs

	// State

	// Results
	Pics []*Pic
}

func (t *ReadIndexPicsTask) Reset() {}

func (t *ReadIndexPicsTask) Run() TaskError {
	var columnNameMap = (&Pic{}).PointerMap()

	var columnNames = make([]string, 0, len(columnNameMap))
	for name, _ := range columnNameMap {
		columnNames = append(columnNames, name)
	}

	stmt := fmt.Sprintf("SELECT %s FROM pix ORDER BY created_time_msec DESC LIMIT 50;",
		strings.Join(columnNames, ","))
	rows, err := t.db.Query(stmt)
	if err != nil {
		return err
	}
	defer rows.Close()

	var pics []*Pic
	for rows.Next() {
		var p = new(Pic)
		pmap := p.PointerMap()

		var rawRowValues = make([]interface{}, 0, len(columnNames))
		for _, columnName := range columnNames {
			rawRowValues = append(rawRowValues, pmap[columnName])
		}
		if err := rows.Scan(rawRowValues...); err != nil {
			return err
		}
		pics = append(pics, p)
	}

	if err := rows.Err(); err != nil {
		return err
	}

	t.Pics = pics

{'fraction_non_alphanumeric': 0.15406162464985995, 'fraction_numerical': 0.0028011204481792717, 'mean_word_length': 3.521097046413502, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6470861', 'n_tokens_mistral': 854, 'n_tokens_neox': 782, 'n_words': 207}