Optimizing for the API
The current rate limit for Facebook's Graph API is 200 calls per hour per user. This means that if your app has 100 users, you can make 20,000 calls per hour. The limit is in aggregate, meaning that any single user could take up all 20,000 calls in that given hour.
To reduce the number of network calls we make to the API, we should tweak our App
component to save feed data within AsyncStorage
and only refresh its data when manually prompted to do so by the user.
We can begin by creating methods for AsyncStorage
, which are similar to the ones we had in Expenses
:
// Friends/app/utils/storageMethods.js import { AsyncStorage } from 'react-native'; export const getAsyncStorage = async (key) => { let response = await AsyncStorage.getItem(key); let parsedData = JSON.parse(response) || {}; return parsedData; } export const setAsyncStorage = async (key, value, callback) => { await AsyncStorage.setItem(key, JSON.stringify(value)); if (callback) { ...