Skip to content

Commit

Permalink
Merge pull request #1957 from jonjove/optimize-load-best-offers
Browse files Browse the repository at this point in the history
Optimize load best offers

Reviewed-by: MonsieurNicolas
  • Loading branch information
latobarita committed Mar 5, 2019
2 parents 001f84e + d5f8996 commit 8d180be
Show file tree
Hide file tree
Showing 9 changed files with 545 additions and 362 deletions.
8 changes: 2 additions & 6 deletions docs/db-schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,8 @@ Field | Type | Description
------|------|---------------
sellerid | VARCHAR(56) NOT NULL | (STRKEY)
offerid | BIGINT NOT NULL CHECK (offerid >= 0) |
sellingassettype | INT | selling.type
sellingassetcode | VARCHAR(12) | selling.*.assetCode
sellingissuer | VARCHAR(56) | selling.*.issuer
buyingassettype | INT | buying.type
buyingassetcode | VARCHAR(12) | buying.*.assetCode
buyingissuer | VARCHAR(56) | buying.*.issuer
sellingasset | TEXT NOT NULL | selling (BASE64)
buyingasset | TEXT NOT NULL | buying (BASE64)
amount | BIGINT NOT NULL CHECK (amount >= 0) |
pricen | INT NOT NULL | Price.n
priced | INT NOT NULL | Price.d
Expand Down
3 changes: 3 additions & 0 deletions src/database/Database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ Database::applySchemaUpgrade(unsigned long vers)
// Update schema for base-64 encoding
mApp.getLedgerTxnRoot().encodeDataNamesBase64();
mApp.getLedgerTxnRoot().encodeHomeDomainsBase64();

// Update schema for simplified offers table
mApp.getLedgerTxnRoot().writeOffersIntoSimplifiedOffersTable();
break;

default:
Expand Down
11 changes: 11 additions & 0 deletions src/ledger/LedgerTxn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1657,6 +1657,11 @@ LedgerTxnRoot::Impl::getBestOffer(Asset const& buying, Asset const& selling,
}
res = findIncludedOffer(newOfferIter, offers.cend(), exclude);
}

if (res)
{
putInEntryCache(getEntryCacheKey(LedgerEntryKey(*res)), res);
}
return res;
}

Expand Down Expand Up @@ -1891,4 +1896,10 @@ LedgerTxnRoot::encodeHomeDomainsBase64()
{
mImpl->encodeHomeDomainsBase64();
}

void
LedgerTxnRoot::writeOffersIntoSimplifiedOffersTable()
{
mImpl->writeOffersIntoSimplifiedOffersTable();
}
}
2 changes: 2 additions & 0 deletions src/ledger/LedgerTxn.h
Original file line number Diff line number Diff line change
Expand Up @@ -598,5 +598,7 @@ class LedgerTxnRoot : public AbstractLedgerTxnParent
void writeSignersTableIntoAccountsTable();
void encodeDataNamesBase64();
void encodeHomeDomainsBase64();

void writeOffersIntoSimplifiedOffersTable();
};
}
6 changes: 6 additions & 0 deletions src/ledger/LedgerTxnImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,12 @@ class LedgerTxnRoot::Impl
// - the prepared statement cache may be, but is not guaranteed to be,
// modified
void encodeHomeDomainsBase64();

// writeOffersIntoSimplifiedOffersTable has the basic exception safety
// guarantee. If it throws an exception, then
// - the prepared statement cache may be, but is not guaranteed to be,
// modified
void writeOffersIntoSimplifiedOffersTable();
};

#ifdef USE_POSTGRES
Expand Down
Loading

0 comments on commit 8d180be

Please sign in to comment.