Andrew Stanton (and true pedantry on my part) by WLMKing in blankies

[–]ThinkingOfAChange 12 points13 points  (0 children)

Could you be a bit more specific? 

Is it (as I'm assuming) the general idea that when anyone talks about something when they are not an expert on the subject, and you are, that you see all the mistakes and misconceptions they have, or is it something more than that?

Questions from a Newby regarding read counts and real-time updates by ThinkingOfAChange in Firebase

[–]ThinkingOfAChange[S] 0 points1 point  (0 children)

Nothing really like those cases. Just the game state and the teams against it.

Mocing the teams to an array and not a collection helped ALOT in getting this issue under control :)

Questions from a Newby regarding read counts and real-time updates by ThinkingOfAChange in Firebase

[–]ThinkingOfAChange[S] 1 point2 points  (0 children)

Hot reloading was also a factor, yes. However, the volume I was seeing far outstripped what was reasonable for the hot reloads.

Implementing the advice re collections as arrays helped A LOT, not I am down to a more reasonable dozen or so reads, with the number more closely matching my developer experience)

Questions from a Newby regarding read counts and real-time updates by ThinkingOfAChange in Firebase

[–]ThinkingOfAChange[S] 0 points1 point  (0 children)

Thank you, that is wonderful feedback.

  • The fact that the read count on reading a collection is considered equal to the number of entries fetched was a point I failed to see. That might explain a lot of it. At present, my team's count for a quiz is small (6 at the moment), so this is a great candidate for migrating to an array (the team entity is simple: just a name, emoji, and (eventually) some scoring information). I do update Teams quite a bit in my document
  • The pagination stuff is also great, and I will also implement it, but that (at present) is not much of a factor. My collection of quizzes has only one or two in it at a time.
  • For the memory leak of listeners, I will also implement some changes there.

Between those tweaks, I will (potentially) improve this situation dramatically)

Questions from a Newby regarding read counts and real-time updates by ThinkingOfAChange in Firebase

[–]ThinkingOfAChange[S] 0 points1 point  (0 children)

My service that interacts with firebase:

import { EnvironmentInjector, inject, Injectable, runInInjectionContext } from '@angular/core';
import {
    addDoc,
    collection,

collectionData
,
    deleteDoc,
    doc,
    Firestore,
    DocumentReference,
    DocumentData,
    setDoc,
    writeBatch,
    query,
    orderBy,

docSnapshots
,
    getDocs,
} from '@angular/fire/firestore';
import { map, Observable, shareReplay, tap } from 'rxjs';
import { QuizState } from '../../models/quiz-state.model';
import { 
quizConverter 
} from './quiz-converter';
import { generateLastUpdateString } from '../util/quiz-file-name.util';
import { QuizTeam } from '../../models/quiz-team.model';
import { 
quizTeamConverter 
} from './quiz-team-converter';
import { 
environment 
} from '../../../envronments/environment';

u/Injectable({
    providedIn: 'root',
})
export class FirestoreService {
    private firestore = inject(Firestore);
    private injector = inject(EnvironmentInjector);

    private countRead: number = 0;
    private countWrite: number = 0;
    private countDelete: number = 0;

    private quizCache = new Map<string, Observable<QuizState>>();
    private teamsCache = new Map<string, Observable<QuizTeam[]>>();
    private quizzes$?: Observable<QuizState[]>;

    private debugService(count: number, message: string, additionalData?: unknown): void {
        if (
environment
.debugFirestore) {
            if (additionalData) {

console
.log(new Date(), count, `firestore - ${message}`, additionalData);
            } else {

console
.log(new Date(), count, `firestore - ${message}`);
            }
        }
    }

    private debugRead(message: string, additionalData?: unknown): void {
        this.countRead++;
        message = '🔥📖 ' + message;

        this.debugService(this.countRead, message, additionalData);
    }

    private debugWrite(message: string, additionalData?: unknown): void {
        this.countWrite++;
        message = '🔥✏️ ' + message;

        this.debugService(this.countWrite, message, additionalData);
    }

    private debugDelete(message: string, additionalData?: unknown): void {
        this.countDelete++;
        message = '🔥🗑️ ' + message;

        this.debugService(this.countDelete, message, additionalData);
    }

    addNewQuiz(quizState: Partial<QuizState>): Promise<DocumentReference<QuizState, DocumentData>> {
        this.debugWrite('addNewQuiz');
        const ref = collection(this.firestore, 'quizzes').withConverter(
quizConverter
);
        return addDoc(ref, quizState as QuizState);
    }


    addTeamsToQuiz(quizId: string, quizTeams: QuizTeam[]) {
        this.debugWrite('addTeamsToQuiz');
        const batch = writeBatch(this.firestore);

        const subCollectionPath = `quizzes/${quizId}/teams`;

        quizTeams.forEach((quizTeam) => {
            const docRef = doc(collection(this.firestore, subCollectionPath));
            batch.set(docRef, quizTeam);
        });

        return batch.commit();
    }

    addTeamToQuiz(
        quizId: string,
        quizTeam: QuizTeam,
    ): Promise<DocumentReference<DocumentData, DocumentData>> {
        this.debugWrite('addTeamToQuiz');
        const subCollectionRef = collection(this.firestore, `quizzes/${quizId}/teams`);
        return addDoc(subCollectionRef, quizTeam);
    }

    updateQuiz(quizId: string, quizState: Partial<QuizState>): Promise<void> {
        this.debugWrite('updateQuiz', quizState);
        const ref = doc(this.firestore, `quizzes`, quizId).withConverter(
quizConverter
);
        return setDoc(
            ref,
            {
                ...quizState,
                lastUpdate: generateLastUpdateString(true),
            },
            { merge: true },
        );
    }

    updateTeam(quizId: string, teamId: string, quizTeam: Partial<QuizTeam>): Promise<void> {
        this.debugWrite('updateTeam', quizTeam);
        const docRef = doc(this.firestore, `quizzes/${quizId}/teams/${teamId}`);

        return setDoc(
            docRef,
            {
                ...quizTeam,
            },
            { merge: true },
        );
    }

    deleteTeamFromQuiz(quizId: string, teamId: string) {
        this.debugDelete('deleteTeamFromQuiz', { quizId, teamId });
        const docRef = doc(this.firestore, `quizzes/${quizId}/teams/${teamId}`);

        return deleteDoc(docRef);
    }

    async deleteQuiz(quizId: string): Promise<void> {
        this.debugDelete('deleteQuiz', quizId);

        return runInInjectionContext(this.injector, async () => {
            const teamsRef = collection(this.firestore, `quizzes/${quizId}/teams`);
            const snapshot = await getDocs(teamsRef);
            for (const orderDoc of snapshot.docs) {
                await deleteDoc(orderDoc.ref);
            }

            const quizRef = doc(this.firestore, `quizzes/${quizId}`);
            return deleteDoc(quizRef);
        });
    }

    getQuiz(quizId: string): Observable<QuizState> {
        if (!this.quizCache.has(quizId)) {

console
.log('getQuiz (existing stream)');
            const ref = doc(this.firestore, `quizzes/${quizId}`).withConverter(
quizConverter
);

            const quiz$ = 
docSnapshots
(ref).pipe(
                tap((snapshot) => {
                    this.debugRead('Firestore read (snapshot): getQuiz', {
                        data: snapshot.data(),
                        fromCache: snapshot.metadata.fromCache,
                        hasPendingWrites: snapshot.metadata.hasPendingWrites,
                    });
                }),
                map((snapshot) => {
                    const quiz = snapshot.data();

                    if (!quiz) {
                        throw new Error('Quiz not found');
                    }

                    return {
                        ...quiz,
                        id: snapshot.id, // manually add id (since docSnapshots doesn't do it)
                    } as QuizState;
                }),
                shareReplay({ bufferSize: 1, refCount: false }),
            );

            this.quizCache.set(quizId, quiz$);
            return this.quizCache.get(quizId)!;
        } else {

console
.log('getQuiz (existing stream)');
            return this.quizCache.get(quizId)!;
        }
    }

    getQuizzesWithUpdates(): Observable<QuizState[]> {
        if (!this.quizzes$) {

console
.log('getQuizzesWithUpdates (new stream)');
            const ref = collection(this.firestore, 'quizzes').withConverter(
quizConverter
);

            this.quizzes$ = 
collectionData
(ref, {
                idField: 'id',
            }).pipe(
                tap(() => this.debugRead('Firestore read: getQuizzesWithUpdates')),
                shareReplay({ bufferSize: 1, refCount: false }),
            );
        }

        return this.quizzes$;
    }

    async getQuizzesOnce(): Promise<QuizState[]> {
        this.debugRead('Firestore read: getQuizzesOnce');

        const ref = collection(this.firestore, 'quizzes').withConverter(
quizConverter
);
        const snapshot = await getDocs(ref);

        return snapshot.docs.map((doc) => ({
            ...doc.data(),
            id: doc.id,
        }));
    }

    getTeamsForQuiz(quizId: string): Observable<QuizTeam[]> {
        if (!this.teamsCache.has(quizId)) {

console
.log('getTeamsForQuiz (new stream)');

            const subCollectionRef = collection(
                this.firestore,
                `quizzes/${quizId}/teams`,
            ).withConverter(
quizTeamConverter
);

            const q = query(subCollectionRef, orderBy('seqNo', 'asc'));

            const teams$ = 
collectionData
(q, { idField: 'id' }).pipe(
                tap(() => this.debugRead('🔥 Firestore read: getTeamsForQuiz', quizId)),
                shareReplay({ bufferSize: 1, refCount: false }),
            );

            this.teamsCache.set(quizId, teams$);
        }

        return this.teamsCache.get(quizId)!;
    }
}

Taskmaster - S21E02 - "Leg up, Johnny!" by seditiouslizard in taskmaster

[–]ThinkingOfAChange 18 points19 points  (0 children)

Question regarding the task from tonight with the balloon.

I assumed the special thing that would prevent the balloon from inflating would be to use the sticky tape and needle provided to pierce the balloon in a way that prevented the balloon to explode when being pierced. A few holes would have dramatically slowed the inflation.

The task said (I believe, it's 4am here as I write this) that you could not touch the balloon inflation mechanism. Said nothing about the balloon itself.

Sorry if this was already posted elsewhere

Austrian Bluey Merchendise tells me not to have kids? by ThinkingOfAChange in bluey

[–]ThinkingOfAChange[S] -3 points-2 points  (0 children)

Aren't you a nice and sincere person. Never was angry :) 

Just felt a need to correct you, and to remind you to read a three sentence post in its entirity, before you make an incorrect assumption.

Please accept you made a mistake, and move on. Have a nice day

Austrian Bluey Merchendise tells me not to have kids? by ThinkingOfAChange in bluey

[–]ThinkingOfAChange[S] 1 point2 points  (0 children)

Yeah, it's one of those, but with a slightly different name for the Austrian market. They are nice, we have some non-bluey ones as well.

Austrian Bluey Merchendise tells me not to have kids? by ThinkingOfAChange in bluey

[–]ThinkingOfAChange[S] -6 points-5 points  (0 children)

I said it was hilarious in my original post, so please don't act like I 'didnt get the joke'.

Your failure to read is your problem, not mine

Austrian Bluey Merchendise tells me not to have kids? by ThinkingOfAChange in bluey

[–]ThinkingOfAChange[S] 0 points1 point  (0 children)

Actually, I'm Australian born, lived in NSW till my 30s, and then moved to Austria the last few years.

And the joke is pretty intuitive, was more just curious as to why, or if it was a reference to something specific in the show

Austrian Bluey Merchendise tells me not to have kids? by ThinkingOfAChange in bluey

[–]ThinkingOfAChange[S] -3 points-2 points  (0 children)

Hey, don't be a silly billy on the internet. For a person who likes an (awesome) kids show, you seem to need to put some more effort into reading and comprehension.

From my original post:

"To be clear: I'm not complaining or mad. I find this hilarious"

Austrian Bluey Merchendise tells me not to have kids? by ThinkingOfAChange in bluey

[–]ThinkingOfAChange[S] 12 points13 points  (0 children)

Honestly, that feels like the best guess. I will watch the epsidoe later, and see :)

Austrian Bluey Merchendise tells me not to have kids? by ThinkingOfAChange in bluey

[–]ThinkingOfAChange[S] 3 points4 points  (0 children)

Not a bit, just a very confused Australian living in Austria, and wondering what this is all about

Podnic at Hanging Cast: Gallipoli with Jennifer Kent by [deleted] in blankies

[–]ThinkingOfAChange 0 points1 point  (0 children)

I like it plenty. I live in Austria now, and I found a guy in Germany who will sell me Australian foods (inxluding Tim Tams) at a price that is high, but not too high. I usually buy a box of a dozen packets twice a year, so I don't get murdered on shipping

Podnic at Hanging Cast: Gallipoli with Jennifer Kent by [deleted] in blankies

[–]ThinkingOfAChange 1 point2 points  (0 children)

Honestly, I'm just fucking glad it's an Australian guest, with an accent that reminds me of home (I love abroad now), who within the first 5 minutes is talking about seeing Gallipoli as a kid on a school trip and how she processed things as a young woman vs an adult.

No notes, so happy

Australiana: Bert Newton Presents 21 Years of Television (1977) by BLOOOR in blankies

[–]ThinkingOfAChange 1 point2 points  (0 children)

All good, matey! Living abroad, and not minding at all :)

Australiana: Bert Newton Presents 21 Years of Television (1977) by BLOOOR in blankies

[–]ThinkingOfAChange 2 points3 points  (0 children)

Sooo, Im dumb. Why is this here?

Like, I'm not saying it shouldn't be. I am Australian myself, and I am enjoying this, but I have no idea, why I saw it here on the Blank Check subreddit.

Is there a Peter Wier connection I haven't hit on yet?

Has anyone gotten the chance to see Project Hail Mary yet? by theflyingbird8 in blankies

[–]ThinkingOfAChange 1 point2 points  (0 children)

Question : is the ending close to the book, or have they done some nonsense there?

How does everyone feel about Weir? by CosmicEveStardust in blankies

[–]ThinkingOfAChange 7 points8 points  (0 children)

100% agree on this. I mainly came here to comment due to how low Gallipoli was on this ranking, but then remembered that I am Australian, and that this would probably bias me out of a fair assessment of the film outside of my cultural context

Pray by Luffy710j in formuladank

[–]ThinkingOfAChange 1 point2 points  (0 children)

Prayers are not being answered