Improve BMA `/tx/history/:pubkey/pending`, `/tx/history/:pubkey/blocks/:from/:to` and `/tx/history/:pubkey/times/:from/:to`

I thhink we cn optimize the response time of BMA /tx/history/:pubkey/pending

In Duniter dev branch, i can see that:

  • in transactions.ts the pubkey's full history is laoded (including sending and received), then filtered :
    async getPendingForPubkey(req: any): Promise<HttpTxHistory> {
      const pubkey = await ParametersService.getPubkeyP(req);
      return this.getFilteredHistory(pubkey, function (res: any) {
        const histo = res.history;
        Underscore.extend(histo, { sent: [], received: [] });
        return res;
      });
    }
    
    private async getFilteredHistory(
      pubkey: string,
      filter: any
      ): Promise<HttpTxHistory> {
        let history = await this.server.dal.getTransactionsHistory(pubkey);
        let result = {
          currency: this.conf.currency,
          pubkey: pubkey,
          history: {
            sending: history.sending.map(dbtx2HttpTxOfHistory),
            received: history.received.map(dbtx2HttpTxOfHistory),
            sent: history.sent.map(dbtx2HttpTxOfHistory),
            pending: history.pending.map(dbtx2HttpTxOfHistory),
          },
        };
      return filter(result);
      }
    }
  • there is not DAL function to get only pending TX, by pubkey
Edited by Benoit Lavenier