<commit_before>import {AdvPrimeMessage} from './adv-growl.model';
import {Observable} from 'rxjs/Observable';
import {Subject} from 'rxjs/Subject';
import 'rxjs/add/operator/map'
import 'rxjs/add/operator/scan'
import 'rxjs/add/observable/of'

enum MESSAGE_SENDER {
    USER,
    CACHE,
    SCHREDDER
}

interface MessageWithSender {
    sender: MESSAGE_SENDER,
    message: AdvPrimeMessage
}

export class AdvGrowlMessageCache {

    private messageCache: Array<AdvPrimeMessage> = []
    private cachedMessage$ = new Subject<MessageWithSender>()
    private schredder$ = new Subject<MessageWithSender>()
    private allocatedMessageSpots: number

    constructor(private maxNumberOfMessages: number) {
        this.allocatedMessageSpots = 0
    }

    getMessages(message$: Observable<AdvPrimeMessage>): Observable<AdvPrimeMessage> {

        return Observable.merge(
            message$.map((message: AdvPrimeMessage) => ({
                sender: MESSAGE_SENDER.USER,
                message: message
            })),
            this.cachedMessage$,
            this.schredder$
        )
            .switchMap((messageWithSender: MessageWithSender) => {
                    switch (messageWithSender.sender) {
                        case MESSAGE_SENDER.USER:
                            if (this.allocatedMessageSpots >= this.maxNumberOfMessages) {
                                this.messageCache.push(messageWithSender.message)
                                return Observable.never()
                            } else {
                                this.allocatedMessageSpots++
                                return Observable.of(messageWithSender.message)
                            }
                        case MESSAGE_SENDER.CACHE:
                            return Observable.of(messageWithSender.message)
                        case MESSAGE_SENDER.SCHREDDER:
                            return Observable.never()
                    }
                }
            )
    }

    deallocateMessageSpot(): void {
        this.allocatedMessageSpots--
        if (this.isCacheEmpty()) {
            this.schredder$.next({sender: MESSAGE_SENDER.SCHREDDER, message: undefined})
        } else {
            const message = this.messageCache.shift()
            this.cachedMessage$.next({sender: MESSAGE_SENDER.CACHE, message: message})
        }
    }

    private isCacheEmpty(): boolean {
        return this.messageCache.length === 0
    }
}
<commit_msg>Fix to many messages created<commit_after>import {AdvPrimeMessage} from './adv-growl.model';
import {Observable} from 'rxjs/Observable';
import {Subject} from 'rxjs/Subject';
import 'rxjs/add/operator/map'
import 'rxjs/add/operator/scan'
import 'rxjs/add/observable/of'

enum MESSAGE_SENDER {
    USER,
    CACHE,
    SCHREDDER
}

interface MessageWithSender {
    sender: MESSAGE_SENDER,
    message: AdvPrimeMessage
}

export class AdvGrowlMessageCache {

    private messageCache: Array<AdvPrimeMessage> = []
    private cachedMessage$ = new Subject<MessageWithSender>()
    private schredder$ = new Subject<MessageWithSender>()
    private allocatedMessageSpots: number

    constructor(private maxNumberOfMessages: number) {
        this.allocatedMessageSpots = 0
    }

    getMessages(message$: Observable<AdvPrimeMessage>): Observable<AdvPrimeMessage> {

        return Observable.merge(
            message$.map((message: AdvPrimeMessage) => ({
                sender: MESSAGE_SENDER.USER,
                message: message
            })),
            this.cachedMessage$,
            this.schredder$
        )
            .switchMap((messageWithSender: MessageWithSender) => {
                    switch (messageWithSender.sender) {
                        case MESSAGE_SENDER.USER:
                            if (this.allocatedMessageSpots >= this.maxNumberOfMessages) {
                                this.messageCache.push(messageWithSender.message)
                                return Observable.never()
                            } else {
                                this.allocatedMessageSpots++
                                return Observable.of(messageWithSender.message)
                            }
                        case MESSAGE_SENDER.CACHE:
                            this.allocatedMessageSpots++
                            return Observable.of(messageWithSender.message)
                        case MESSAGE_SENDER.SCHREDDER:
                            return Observable.never()
                    }
                }
            )
    }

    deallocateMessageSpot(): void {
        this.allocatedMessageSpots--
        if (this.isCacheEmpty()) {
            this.schredder$.next({sender: MESSAGE_SENDER.SCHREDDER, message: undefined})
        } else {
            const message = this.messageCache.shift()
            this.cachedMessage$.next({sender: MESSAGE_SENDER.CACHE, message: message})
        }
    }

    private isCacheEmpty(): boolean {
        return this.messageCache.length === 0
    }
}

{'fraction_non_alphanumeric': 0.088141663350577, 'fraction_numerical': 0.0007958615200955034, 'mean_word_length': 1.8005571030640668, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 19, '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': '3417614', 'n_tokens_mistral': 1342, 'n_tokens_neox': 1269, 'n_words': 227}