<commit_before>package db

import (
	"time"

	"github.com/deiwin/luncher-api/db/model"
	"gopkg.in/mgo.v2"
	"gopkg.in/mgo.v2/bson"
)

type Offers interface {
	Insert(...*model.Offer) ([]*model.Offer, error)
	GetForRegion(region string, startTime, endTime time.Time) ([]*model.Offer, error)
	GetForRestaurant(restaurantName string, startTime time.Time) ([]*model.Offer, error)
	UpdateID(bson.ObjectId, *model.Offer) error
	GetID(bson.ObjectId) (*model.Offer, error)
}

type offersCollection struct {
	*mgo.Collection
}

func NewOffers(client *Client) Offers {
	collection := client.database.C(model.OfferCollectionName)
	return &offersCollection{collection}
}

func (c offersCollection) Insert(offersToInsert ...*model.Offer) ([]*model.Offer, error) {
	for _, offer := range offersToInsert {
		if offer.ID == "" {
			offer.ID = bson.NewObjectId()
		}
	}
	docs := make([]interface{}, len(offersToInsert))
	for i, offer := range offersToInsert {
		docs[i] = offer<commit_msg>update offersCollection init to ensure indexes<commit_after>package db

import (
	"time"

	"github.com/deiwin/luncher-api/db/model"
	"gopkg.in/mgo.v2"
	"gopkg.in/mgo.v2/bson"
)

type Offers interface {
	Insert(...*model.Offer) ([]*model.Offer, error)
	GetForRegion(region string, startTime, endTime time.Time) ([]*model.Offer, error)
	GetForRestaurant(restaurantName string, startTime time.Time) ([]*model.Offer, error)
	UpdateID(bson.ObjectId, *model.Offer) error
	GetID(bson.ObjectId) (*model.Offer, error)
}

type offersCollection struct {
	*mgo.Collection
}

func NewOffers(client *Client) Offers {
	collection := client.database.C(model.OfferCollectionName)
	offers := &offersCollection{collection}
	offers.ensureOffersTTLIndex()
	offers.ensureOffersHaystackIndex()
	return offers
}

func (c offersCollection) Insert(offersToInsert ...*model.Offer) ([]*model.Offer, error) {
	for _, offer := range offersToInsert {
		if offer.ID == "" {
			offer.ID = bson.NewObjectId()
		}
	}
	docs := make([]interface{}, len(offersToInsert))
	for i, offer := range offersToInsert {
		docs[i] = offer
{'fraction_non_alphanumeric': 0.14951456310679612, 'fraction_numerical': 0.001941747572815534, 'mean_word_length': 5.133928571428571, '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': '2913462', 'n_tokens_mistral': 783, 'n_tokens_neox': 752, 'n_words': 146}