package com.chistacoOrNot

class JokeService {
    
    static transactional = true
    
    public List<Joke> nextJokes() {
        def jokeIds = Joke.withCriteria {
            projections {
                property('id')
            }
        }
        
        def randomList = jokeIds.sort { Math.random() }
        def joke1 = Joke.get(randomList[0])
        def joke2 = Joke.get(randomList[1])
        
        return [joke1, joke2]
    }

    public Boolean vote(Joke joke) {
        joke.points++
        joke.save()
        
        return true
    }
}

package com.chistacoOrNot

class JokeService {
    
    static transactional = false

    /**
     * Return two random jokes
     *
     * @return two random jokes
     */    
    public List<Joke> nextJokes() {
        def jokes = Joke.withCriteria {
            sqlRestriction "1=1 order by random()"
            maxResults 2
        }

        return jokes
    }

    /**
     * Add a point to a joke
     *
     * @param The joke to vote
     * @return true when done
     */
    public Boolean vote(Joke joke) {
        joke.points++
        joke.save()
        
        return true
    }
}

Return two random jokes with postgres random() function
Return two random jokes with postgres random() function
