Skip to content
This repository has been archived by the owner on Mar 16, 2023. It is now read-only.

Commit

Permalink
feat(sdk): fix for incorrectly indexing notes for linked accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
joeandrews committed Mar 30, 2020
1 parent fc56d87 commit 57d38cf
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
39 changes: 37 additions & 2 deletions packages/extension/src/background/database/helpers/Model/latest.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,43 @@
import {
errorLog,
} from '~/utils/log';
import {
getDB,
} from '../..';

export default async function latest(modelName, { networkId }, { orderBy }) {
export default async function latest(
modelName,
{ networkId },
{
orderBy,
filterOptions,
},
) {
if (!orderBy) {
errorLog(`Field 'orderBy' is required to get the latest ${modelName}.`);
return null;
}

let matchingIds;
if (filterOptions) {
const query = getDB(networkId)[modelName].where(filterOptions);
matchingIds = new Set(await query.primaryKeys());
if (!matchingIds.size) {
return null;
}
}

const table = getDB(networkId)[modelName];
return table.orderBy(orderBy).last();
let targetId;
await table
.orderBy(orderBy)
.reverse()
.until(() => !!targetId)
.eachPrimaryKey(async (id) => {
if (!matchingIds || matchingIds.has(id)) {
targetId = id;
}
});

return targetId ? table.get(targetId) : null;
}
14 changes: 9 additions & 5 deletions packages/extension/src/background/services/EventService/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,18 @@ class EventService {
const assets = await this.syncedAssets({ networkId });
assetsHandler(assets);
}
const options = {
// orderBy: 'blockNumber',
};

const lastSyncedAsset = await Asset.latest({ networkId });
// const lastSyncedAsset = await Asset.latest({ networkId }, options);

// TODO: Improve this for each network separately
let lastSyncedBlock = START_EVENTS_SYNCING_BLOCK;
const lastSyncedBlock = START_EVENTS_SYNCING_BLOCK;

if (lastSyncedAsset) {
lastSyncedBlock = lastSyncedAsset.blockNumber;
}
// if (lastSyncedAsset) {
// lastSyncedBlock = lastSyncedAsset.blockNumber;
// }

manager.sync({
lastSyncedBlock,
Expand Down Expand Up @@ -240,6 +243,7 @@ class EventService {
blockNumber: assetBlockNumber,
} = asset;
const options = {
orderBy: 'blockNumber',
filterOptions: {
asset: registryOwner,
owner: address,
Expand Down

0 comments on commit 57d38cf

Please sign in to comment.