<commit_before>package modelhelper

import (
	"koding/db/models"
	"time"

	"gopkg.in/mgo.v2"
	"gopkg.in/mgo.v2/bson"
)

const DeletedMembersCollectionName = "jDeletedMembers"

// GetDeletedMemberCountByGroupId counts the deleted users with groupId
func GetDeletedMemberCountByGroupId(groupID bson.ObjectId) (int, error) {
	var count int
	query := countQuery(Selector{
		"subscriptionId": bson.M{"$exists": false},
		"groupId":        groupID,
	}, Options{}, &count)

	return count, Mongo.Run(DeletedMembersCollectionName, query)
}

// CalculateAndApplyDeletedMembers counts the deleted users and marks them as
// operated for future invoices
func CalculateAndApplyDeletedMembers(groupID bson.ObjectId, subscriptionID string) (int, error) {
	var changeInfo *mgo.ChangeInfo
	var err error
	query := func(c *mgo.Collection) error {
		query := bson.M{
			"subscriptionId": bson.M{"$exists": false},
			"groupId":        groupID,
		}

		change := bson.M{
			"$set": bson.M{
				"subscriptionId": subscriptionID,
				"updatedAt":      time.Now(),
			},
		}

		changeInfo, err = c.UpdateAll(query, change)<commit_msg>go: use UTC in time<commit_after>package modelhelper

import (
	"koding/db/models"
	"time"

	"gopkg.in/mgo.v2"
	"gopkg.in/mgo.v2/bson"
)

const DeletedMembersCollectionName = "jDeletedMembers"

// GetDeletedMemberCountByGroupId counts the deleted users with groupId
func GetDeletedMemberCountByGroupId(groupID bson.ObjectId) (int, error) {
	var count int
	query := countQuery(Selector{
		"subscriptionId": bson.M{"$exists": false},
		"groupId":        groupID,
	}, Options{}, &count)

	return count, Mongo.Run(DeletedMembersCollectionName, query)
}

// CalculateAndApplyDeletedMembers counts the deleted users and marks them as
// operated for future invoices
func CalculateAndApplyDeletedMembers(groupID bson.ObjectId, subscriptionID string) (int, error) {
	var changeInfo *mgo.ChangeInfo
	var err error
	query := func(c *mgo.Collection) error {
		query := bson.M{
			"subscriptionId": bson.M{"$exists": false},
			"groupId":        groupID,
		}

		change := bson.M{
			"$set": bson.M{
				"subscriptionId": subscriptionID,
				"updatedAt":      time.Now().UTC(),
			},
		}

		changeInfo, err = c.UpdateAll(query, change)
{'fraction_non_alphanumeric': 0.12455197132616487, 'fraction_numerical': 0.0017921146953405018, 'mean_word_length': 4.393719806763285, 'pattern_counts': {'":': 18, '<': 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': '6609464', 'n_tokens_mistral': 798, 'n_tokens_neox': 752, 'n_words': 177}