<commit_before>package models

import (
	"fmt"
	"log"

	"code.google.com/p/go-uuid/uuid"

	"github.com/ninjasphere/go-ninja/model"
	"github.com/ninjasphere/redigo/redis"
)

type RoomModel struct {
	baseModel

	ThingModel *ThingModel `inject:""`
}

func toRoom(obj interface{}) *model.Room {
	var thing, ok = obj.(*model.Room)
	if !ok {
		panic("Non-'Room' passed to a RoomModel handler")
	}
	return thing
}

func NewRoomModel() *RoomModel {

	roomModel := &RoomModel{
		baseModel: newBaseModel("room", model.Room{}),
	}
	roomModel.baseModel.afterDelete = func(obj interface{}) error {
		return roomModel.afterDelete(toRoom(obj))
	}

	return roomModel
}

func (m *RoomModel) PostConstruct() error {

	log.Printf("Checking for bad rooms...")

	// Check all rooms to see if we have any without an ID.
	// Delete any that are missing an ID.
	ids, err := m.fetchIds()

	if err != nil {
		return err
	}

	for _, id := range ids {
		room, err := m.Fetch(id)
		if err != nil || !m.isValid(room) {
			log.Printf("Bad room! ID: %s Room: %+v", id, room)
			m.Delete(id)
		}
	}

	return nil
}

// Do more here. Use the schemas.
func (m *RoomModel) isValid(room *model.Room) bool {
	return room.ID != ""
}

func (m *RoomModel) Create(room *model.Room) error {
	m.syncing.Wait()
	//defer m.sync()

	if room.ID == "" {
		room.ID = uuid.NewUUID().String()
	}

	_, err := m.save(room.ID, room)
	return err
}

func (m *RoomModel) Fetch(id string) (*model.Room, error) {
	m.syncing.Wait()

	room := &model.Room{}

	if err := m.fetch(id, room, false); err != nil {<commit_msg>Use random UUID for rooms<commit_after>package models

import (
	"fmt"
	"log"

	"code.google.com/p/go-uuid/uuid"

	"github.com/ninjasphere/go-ninja/model"
	"github.com/ninjasphere/redigo/redis"
)

type RoomModel struct {
	baseModel

	ThingModel *ThingModel `inject:""`
}

func toRoom(obj interface{}) *model.Room {
	var thing, ok = obj.(*model.Room)
	if !ok {
		panic("Non-'Room' passed to a RoomModel handler")
	}
	return thing
}

func NewRoomModel() *RoomModel {

	roomModel := &RoomModel{
		baseModel: newBaseModel("room", model.Room{}),
	}
	roomModel.baseModel.afterDelete = func(obj interface{}) error {
		return roomModel.afterDelete(toRoom(obj))
	}

	return roomModel
}

func (m *RoomModel) PostConstruct() error {

	log.Printf("Checking for bad rooms...")

	// Check all rooms to see if we have any without an ID.
	// Delete any that are missing an ID.
	ids, err := m.fetchIds()

	if err != nil {
		return err
	}

	for _, id := range ids {
		room, err := m.Fetch(id)
		if err != nil || !m.isValid(room) {
			log.Printf("Bad room! ID: %s Room: %+v", id, room)
			m.Delete(id)
		}
	}

	return nil
}

// Do more here. Use the schemas.
func (m *RoomModel) isValid(room *model.Room) bool {
	return room.ID != ""
}

func (m *RoomModel) Create(room *model.Room) error {
	m.syncing.Wait()
	//defer m.sync()

	if room.ID == "" {
		room.ID = uuid.NewRandom().String()
	}

	_, err := m.save(room.ID, room)
	return err
}

func (m *RoomModel) Fetch(id string) (*model.Room, error) {
	m.syncing.Wait()

	room := &model.Room{}

	if err := m.fetch(id, room, false); err != nil {
{'fraction_non_alphanumeric': 0.163787587971849, 'fraction_numerical': 0.0, 'mean_word_length': 3.4735336194563664, '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': '4898748', 'n_tokens_mistral': 1236, 'n_tokens_neox': 1186, 'n_words': 316}