Пример #1
0
// recordStoryVote adds a vote record for this user
func recordStoryVote(story *stories.Story, user *users.User, ip string, delta int64) error {

	// Add an entry in the votes table
	// FIXME: adjust query to do this for us we should use ?,?,? here...
	// $1, $2 is surprising, shouldn't we expect query package to deal with this for us?
	_, err := query.Exec("insert into votes VALUES(now(),NULL,$1,$2,$3,$4)", story.Id, user.Id, ip, delta)
	if err != nil {
		return router.InternalError(err, "Vote Failed", "Sorry your vote failed to record")
	}

	return nil
}
Пример #2
0
// updateStoriesRank updates the rank of all stories with a rank based on their point score / time elapsed (as represented by id)
//  to the power of gravity
//    update stories set rank = points / POWER((select count(*) from stories) - id + 1,1.8);
// Similar to HN ranking scheme
func updateStoriesRank() error {
	sql := "update stories set rank = 100 * points / POWER((select max(id) from stories) - id + 1,1.2)"
	_, err := query.Exec(sql)
	return err
}
Пример #3
0
// updateCommentsRank updates the rank of comments on this story
func updateCommentsRank(storyID int64) error {
	sql := "update comments set rank = 100 * points / POWER((select max(id) from comments) - id + 1,1.2) where story_id=$1"
	_, err := query.Exec(sql, storyID)
	return err
}