我正在地圖項目中實時使用 firestore,它需要以 x 距離間隔更新用戶的當前位置。但是,實時偵聽器不斷重新獲取我自己的更新,從而增加了我的閱讀量。我假設 firestore 在發送到服務器之前會實時更新本地緩存,是否可以忽略該用戶所做的更改?class Booking extends Component { constructor(props) { super(props); this.state = { isLoading: false, errorMessage: '', }; this.unsubscribe = null; } componentDidMount() { this.getRealTimeData(); } componentWillUnmount() { this.unsubscribe = null; } getRealTimeData = () => { this.fetchCompletedGigs(); } fetchCompletedGigs = () => { const { userID } = this.props; this.props.bookingData([]); this.setState({ isLoading: true, errorMessage: '' }); this.unsubscribe = Firebase.shared.fetchBooking('Bookings') .where('userID', '==', userID) .orderBy('d.CreatedAt', 'desc') .limit(20) .onSnapshot((querySnapshot) => { if (querySnapshot.empty) { this.setState({ isLoading: false, errorMessage: "You currently don't have anybooking", }); this.props.bookingData([]); } querySnapshot.docChanges().forEach(change => { const doc = change.doc; const item = doc.data(); item.docId = doc.id; const list = [...this.props.bookings, item]; this.setState({ isLoading: false, errorMessage: '' }); if (change.type === 'added') { const filterList = _.uniqBy(list, 'docId'); this.props.bookingData(filterList); } else if (change.type === 'removed') { const newData = list.filter(task => task.docId !== doc.id); const filterList = _.uniqBy(newData, 'docId'); return this.props.bookingData(filterList); } else if (change.type === 'modified') { const newData = list.filter(task => task.docId !== doc.id); const newList = [...newData, item]; const filterList = _.uniqBy(newList, 'docId'); return this.props.bookingData(filterList); } }
檢查消防倉庫的實時變化
狐的傳說
2022-09-23 21:30:59