<commit_before>package models

import (
	"database/sql"

	e "github.com/techjanitor/pram-post/errors"
	u "github.com/techjanitor/pram-post/utils"
)

type DeletePostModel struct {
	Thread  uint
	Id      uint
	Ib      uint
	Name    string
	Deleted bool
}

// Status will return info
func (i *DeletePostModel) Status() (err error) {

	// Get Database handle
	db, err := u.GetDb()
	if err != nil {
		return
	}

	// get thread ib and title
	err = db.QueryRow(`SELECT ib_id, thread_title, post_deleted FROM threads 
	INNER JOIN posts on threads.thread_id = posts.thread_id
	WHERE threads.thread_id = ? LIMIT 1`, i.Thread).Scan(&i.Ib, &i.Name, &i.Deleted)
	if err == sql.ErrNoRows {
		return e.ErrNotFound
	} else if err != nil {
		return
	}

	return

}

// Delete will remove the entry
func (i *DeletePostModel) Delete() (err error) {

	// Get transaction handle
	tx, err := u.GetTransaction()
	if err != nil {
		return
	}
	defer tx.Rollback()

	var lasttime string

	// get last post time
	err = tx.QueryRow("SELECT post_time FROM posts 
	WHERE thread_id = ? AND post_deleted != 1
	ORDER BY post_id DESC LIMIT 1", i.Thread).Scan(&lasttime)
	if err != nil {
		return
	}

	// set post to deleted
	ps1, err := tx.Prepare(`UPDATE posts SET post_deleted = ?
	WHERE posts.thread_id = ? AND posts.post_num = ? LIMIT 1`)
	if err != nil {
		return
	}
	defer ps1.Close()

	// update last post time in thread
	ps2, err := tx.Prepare("UPDATE threads SET thread_last_post= ? WHERE thread_id= ?")
	if err != nil {
		return
	}
	defer ps2.Close()
<commit_msg>update last thread post on post deletion<commit_after>package models

import (
	"database/sql"

	e "github.com/techjanitor/pram-post/errors"
	u "github.com/techjanitor/pram-post/utils"
)

type DeletePostModel struct {
	Thread  uint
	Id      uint
	Ib      uint
	Name    string
	Deleted bool
}

// Status will return info
func (i *DeletePostModel) Status() (err error) {

	// Get Database handle
	db, err := u.GetDb()
	if err != nil {
		return
	}

	// get thread ib and title
	err = db.QueryRow(`SELECT ib_id, thread_title, post_deleted FROM threads 
	INNER JOIN posts on threads.thread_id = posts.thread_id
	WHERE threads.thread_id = ? LIMIT 1`, i.Thread).Scan(&i.Ib, &i.Name, &i.Deleted)
	if err == sql.ErrNoRows {
		return e.ErrNotFound
	} else if err != nil {
		return
	}

	return

}

// Delete will remove the entry
func (i *DeletePostModel) Delete() (err error) {

	// Get transaction handle
	tx, err := u.GetTransaction()
	if err != nil {
		return
	}
	defer tx.Rollback()

	var lasttime string

	// get last post time
	err = tx.QueryRow(`SELECT post_time FROM posts 
	WHERE thread_id = ? AND post_deleted != 1
	ORDER BY post_id DESC LIMIT 1`, i.Thread).Scan(&lasttime)
	if err != nil {
		return
	}

	// set post to deleted
	ps1, err := tx.Prepare(`UPDATE posts SET post_deleted = ?
	WHERE posts.thread_id = ? AND posts.post_num = ? LIMIT 1`)
	if err != nil {
		return
	}
	defer ps1.Close()

	// update last post time in thread
	ps2, err := tx.Prepare("UPDATE threads SET thread_last_post= ? WHERE thread_id= ?")
	if err != nil {
		return
	}
	defer ps2.Close()

{'fraction_non_alphanumeric': 0.11537222043184016, 'fraction_numerical': 0.00515630035449565, 'mean_word_length': 3.2346521145975444, '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': '470812', 'n_tokens_mistral': 1138, 'n_tokens_neox': 1098, 'n_words': 346}