Repository: gventuri/pandas-ai
File: pandasai/connectors/airtable.py (Python)

Code before:
            df (DataFrame): The DataFrame to save to the cache.
        """
        filename = self._get_cache_path(
            include_additional_filters=self._additional_filters is not None
            and len(self._additional_filters) > 0
        )
        df.to_parquet(filename)

    @property
    def fallback_name(self):
        """
        Returns the fallback table name of the connector.

        Returns :
            str : The fallback table name of the connector.
        """
        return self._config.table

    def execute(self):
        """
        Execute the connector and return the result.

        Returns:
            DataFrameType: The result of the connector.
        """
        return self.fetch_data()

    def build_formula(self):
        """
        Build Airtable query formula for filtering.
        """

        condition_strings = []
        for i in self._config.where:
            filter_query = f"{i[0]}{i[1]}'{i[2]}'"
            condition_strings.append(filter_query)
        filter_formula = f'AND({",".join(condition_strings)})'
        return filter_formula

    def fetch_data(self):
        """
        Feteches data from airtable server through
            API and converts it to DataFrame.
        """
        url = f"{self._root_url}{self._config.base_id}/{self._config.table}"
        params = {}

        if self._config.where:
            params["filterByFormula"] = self.build_formula()
        response = requests.get(
            url=url,

Review comment (performance):
You have cached it but never used it. You can for the cache like:

cached = self._cached() or self._cached(include_additional_filters=True)
        if cached:
            return pd.read_parquet(cached)



Code after:
    def _save_cache(self, df):
        """
        Save the given DataFrame to the cache.

        Args:
            df (DataFrame): The DataFrame to save to the cache.
        """
        filename = self._get_cache_path(
            include_additional_filters=self._additional_filters is not None
            and len(self._additional_filters) > 0
        )
        df.to_parquet(filename)

    @property
    def fallback_name(self):
        """
        Returns the fallback table name of the connector.

        Returns :
            str : The fallback table name of the connector.
        """
        return self._config.table

    def execute(self):
        """
        Execute the connector and return the result.

        Returns:
            DataFrameType: The result of the connector.
        """
        cached = self._cached() or self._cached(include_additional_filters=True)
        if cached:
            return pd.read_parquet(cached)

        if isinstance(self._instance, pd.DataFrame):
            return self._instance
        else:
            self._instance = self._fetch_data()

        return self._instance

    def _build_formula(self):
        """
        Build Airtable query formula for filtering.
        """

        condition_strings = []
        if self._config.where is not None:
            for i in self._config.where:
                filter_query = f"{i[0]}{i[1]}'{i[2]}'"
                condition_strings.append(filter_query)