וכל זה ב7-8 הכי הרבה 10
//servise אנגולר
import {Injectable} from '@angular/core';
import {AngularFirestore} from '@angular/fire/compat/firestore';
import {catchError} from 'rxjs/operators';
import {throwError} from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class DataService
{
videos: any[] = []
errorVideos: any = false
users: any = false
constructor (private firestore: AngularFirestore)
{
this.getvideos();
}
getvideos ()
{
if (this.videos.length === 0 && !this.errorVideos)
{
this.firestore.collection('videos')
.valueChanges()
.pipe(
catchError(error =>
{
this.errorVideos = {
text: error.message
}
if (localStorage.getItem('videos') != null)
{
let string: any = localStorage.getItem('videos')
this.videos = JSON.parse(string)
this.errorVideos.timevideos = localStorage.getItem('timevideos')
console.log(this.videos)
}
return throwError(error);
})
)
.subscribe(data =>
{
this.videos = data;
console.log(this.videos)
let string = JSON.stringify(this.videos)
localStorage.setItem('videos', string)
localStorage.setItem('timevideos', '' + new Date().getTime())
});
}
}
}
ובמילים פשוטות בconstrctor(בנאי מופעל ברגע הראשון)
יש קריאה ל
this.getvideos();
ששולח קריאה לfirebase לקבל את כל הcollection
( this.firestore.collection('videos')
.valueChanges())
ולשמור אותו במשתנה videos וכל זה רק במקרה שעדיין הוא ריק (כי יש כמה מקומות שמשתמשים בservise הזה)
(כל מה שלפני הsubscribe זה טיפול בשגיאות)
מספר פעמים רעננתי את הדף (כי הרי הוא לא יקרא לנתונים פעמים באותו כניסה)
ואחרי מספר פעמים
התמונות למעלה
תגובת הקונסול
ROR FirebaseError: Quota exceeded.
h
בקולקשן (collection) videos יש 3579 אובייקטים שמכילים
date סטרינג
id סטרינג
img אוביקט עם url , אורך ורוחב כולם סטירינג (רוחב ואורך מספר)
name סטרינג
text סטרינג
userid סטרינג
אבל בfirebase זה נראה כאילו קראתי יותר מ50000 (50k) פעם
יכול להיות שזה לפי אוביקט ולא לפי קריאה ?