<commit_before>package streams

import (
	"github.com/MediaMath/keryxlib/filters"
	"github.com/MediaMath/keryxlib/message"
	"github.com/MediaMath/keryxlib/pg/wal"
)

//TxnBuffer is a stream of WAL entries organized by transaction
type TxnBuffer struct {
	f                      filters.MessageFilter
	bufferWorkingDirectory string
}

//Start takes a channel of WAL entries and async selects on it.  As it finds a commit for a transaction it publishes a slice of the entries in that transaction.  Aborted transactions are not published.
func (b *TxnBuffer) Start(entryChan <-chan *wal.Entry) (<-chan []*wal.Entry, error) {
	txns := make(chan []*wal.Entry)

	go func() {
		buffer := message.NewBuffer(b.bufferWorkingDirectory, 10*1024*wal.EntryBytesSize, wal.EntryBytesSize)
		var lastEntry *wal.Entry
		for entry := range entryChan {
			if lastEntry != nil && lastEntry.ReadFrom.Offset() > entry.ReadFrom.Offset() {
				continue
			} else if entry.Type == wal.Unknown {
				continue
			} else if b.f.FilterRelID(entry.RelationID) {
				continue
			}

			lastEntry = entry

			if entry.Type == wal.Commit {
				entriesBytes := buffer.Remove(entry.TransactionID)
				var entries []*wal.Entry
				for _, entryBytes := range entriesBytes {
					e := wal.EntryFromBytes(entryBytes)
					entries = append(entries, &e)
				}
				entries = append(entries, entry)
				txns <- entries
			} else if entry.Type == wal.Abort {
				buffer.Remove(entry.TransactionID)
			} else {
				buffer.Add(entry.TransactionID, entry.ToBytes())
			}

		}
		close(txns)
	}()

	return txns, nil
}<commit_msg>updated filters to not filter commits<commit_after>package streams

import (
	"github.com/MediaMath/keryxlib/filters"
	"github.com/MediaMath/keryxlib/message"
	"github.com/MediaMath/keryxlib/pg/wal"
)

//TxnBuffer is a stream of WAL entries organized by transaction
type TxnBuffer struct {
	f                      filters.MessageFilter
	bufferWorkingDirectory string
}

//Start takes a channel of WAL entries and async selects on it.  As it finds a commit for a transaction it publishes a slice of the entries in that transaction.  Aborted transactions are not published.
func (b *TxnBuffer) Start(entryChan <-chan *wal.Entry) (<-chan []*wal.Entry, error) {
	txns := make(chan []*wal.Entry)

	go func() {
		buffer := message.NewBuffer(b.bufferWorkingDirectory, 10*1024*wal.EntryBytesSize, wal.EntryBytesSize)
		var lastEntry *wal.Entry
		for entry := range entryChan {
			if lastEntry != nil && lastEntry.ReadFrom.Offset() > entry.ReadFrom.Offset() {
				continue
			} else if entry.Type == wal.Unknown {
				continue
			} else if entry.Type != wal.Commit && b.f.FilterRelID(entry.RelationID) {
				continue
			}

			lastEntry = entry

			if entry.Type == wal.Commit {
				entriesBytes := buffer.Remove(entry.TransactionID)
				var entries []*wal.Entry
				for _, entryBytes := range entriesBytes {
					e := wal.EntryFromBytes(entryBytes)
					entries = append(entries, &e)
				}
				entries = append(entries, entry)
				txns <- entries
			} else if entry.Type == wal.Abort {
				buffer.Remove(entry.TransactionID)
			} else {
				buffer.Add(entry.TransactionID, entry.ToBytes())
			}

		}
		close(txns)
	}()

	return txns, nil
}
{'fraction_non_alphanumeric': 0.11097256857855362, 'fraction_numerical': 0.003740648379052369, 'mean_word_length': 3.3958904109589043, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, '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': '1508977', 'n_tokens_mistral': 1167, 'n_tokens_neox': 999, 'n_words': 275}