Skip to content

Commit

Permalink
fix: removed unused library
Browse files Browse the repository at this point in the history
  • Loading branch information
raghukapur9 committed Sep 14, 2024
1 parent 0065069 commit 87311eb
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import { z } from 'zod';
import { act } from '~/systems/Core/utils/act-server';
import { sdk } from '~/systems/Core/utils/sdk';
import { DateHelper } from '../utils/date';
import {
createIntervals,
getUnitAndInterval,
Expand Down Expand Up @@ -43,10 +42,8 @@ async function fetchAccountStatistics(
return isCumulative ? { accounts: [], offset: 0 } : { accounts: [] };
}

const firstTimestamp = Number(DateHelper.tai64toDate(nodes[0].timestamp));
const lastTimestamp = Number(
DateHelper.tai64toDate(nodes[nodes.length - 1].timestamp),
);
const firstTimestamp = Number(nodes[0].timestamp);
const lastTimestamp = Number(nodes[nodes.length - 1].timestamp);

const intervalMap = createIntervals(
firstTimestamp,
Expand Down
6 changes: 5 additions & 1 deletion packages/app-explorer/src/systems/Statistics/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ interface TransactionNode {
timestamp: string;
}

interface AccountNode {
timestamp: string;
}

interface Interval {
start: Date;
end: Date;
Expand Down Expand Up @@ -178,7 +182,7 @@ export function processTransactions(
// Helper to process accounts and map to intervals
export function processAccounts(nodes: AccountNode[], intervalMap: Interval[]) {
nodes.forEach((account) => {
const accountTimestamp = Number(DateHelper.tai64toDate(account.timestamp));
const accountTimestamp = Number(account.timestamp);

// Find the correct interval for the current account
for (const interval of intervalMap) {
Expand Down
3 changes: 3 additions & 0 deletions packages/graphql/src/graphql/resolvers/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AccountResolver } from './AccountResolver';
import { BalanceResolver } from './BalanceResolver';
import { BlockResolver } from './BlockResolver';
import { ChainResolver } from './ChainResolver';
Expand All @@ -15,6 +16,7 @@ const nodeResolver = NodeResolver.create();
const predicateResolver = PredicateResolver.create();
const searchResolver = SearchResolver.create();
const transactionResolver = TransactionResolver.create();
const accountResolver = AccountResolver.create();

export const resolvers = {
Query: {
Expand All @@ -26,6 +28,7 @@ export const resolvers = {
...predicateResolver.Query,
...searchResolver.Query,
...transactionResolver.Query,
...accountResolver.Query,
},
Balance: balanceResolver.Balance,
};
55 changes: 34 additions & 21 deletions packages/graphql/src/infra/dao/AccountDAO.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { DateHelper } from '~/core/Date';
import { AccountEntity } from '../../domain/Account/AccountEntity';
import { DatabaseConnection } from '../database/DatabaseConnection';
import { getTimeInterval } from './utils';
Expand Down Expand Up @@ -116,34 +115,43 @@ export default class AccountDAO {

let query = `
SELECT
(data->'first_transaction_timestamp')::bigint AS timestamp
first_transaction_timestamp AS timestamp
FROM indexer.accounts
`;

let intervalStartTimeTai64 = '';
let intervalStartTimeDate = '';

if (_interval) {
const intervalStartTimeInMilliseconds = Date.now() - _interval;
const intervalStartTimeDate = new Date(intervalStartTimeInMilliseconds);
intervalStartTimeTai64 = DateHelper.dateToTai64(intervalStartTimeDate);
query += `WHERE (data->'first_transaction_timestamp')::bigint >= ${intervalStartTimeTai64}`;
intervalStartTimeDate = new Date(
intervalStartTimeInMilliseconds,
).toISOString();

// Add the WHERE clause, parameterizing the date value to ensure proper handling
query += 'WHERE first_transaction_timestamp >= $1';
}

query += ' ORDER BY timestamp asc';
query += ' ORDER BY timestamp ASC';

const accountsData = await this.databaseConnection.query(query, []);
// Execute the main query with the interval start date as a parameter
const accountsData = await this.databaseConnection.query(query, [
intervalStartTimeDate,
]);

// Calculate accountOffset: Accounts created before the first timestamp in the interval
const offsetQuery = `
SELECT COUNT(*) as accountOffset
SELECT COUNT(*) as "accountOffset"
FROM indexer.accounts
WHERE (data->'first_transaction_timestamp')::bigint < ${intervalStartTimeTai64}
WHERE first_transaction_timestamp < $1
`;
const offsetResult = await this.databaseConnection.query(offsetQuery, []);

const offsetResult = await this.databaseConnection.query(offsetQuery, [
intervalStartTimeDate,
]);

return {
nodes: accountsData,
accountOffset: offsetResult[0].accountoffset || 0,
accountOffset: offsetResult[0].accountOffset || 0,
};
}

Expand All @@ -152,23 +160,28 @@ export default class AccountDAO {

let query = `
SELECT
COUNT(*) as count,
(data->'first_transaction_timestamp')::bigint AS timestamp
first_transaction_timestamp AS timestamp
FROM indexer.accounts
`;
// Prepare interval start time as a valid ISO string
let intervalStartTimeDate = '';

if (_interval) {
const intervalStartTimeInMilliseconds = Date.now() - _interval;
const intervalStartTimeDate = new Date(intervalStartTimeInMilliseconds);
const intervalStartTimeTai64 = DateHelper.dateToTai64(
intervalStartTimeDate,
);
query += `WHERE (data->'first_transaction_timestamp')::bigint >= ${intervalStartTimeTai64}`;
intervalStartTimeDate = new Date(
intervalStartTimeInMilliseconds,
).toISOString();

// Add the WHERE clause, parameterizing the date value to ensure proper handling
query += 'WHERE first_transaction_timestamp >= $1';
}

query += ' ORDER BY timestamp asc';
query += ' ORDER BY timestamp ASC';

const accountsData = await this.databaseConnection.query(query, []);
// Execute the main query with the interval start date as a parameter
const accountsData = await this.databaseConnection.query(query, [
intervalStartTimeDate,
]);

return {
nodes: accountsData,
Expand Down

0 comments on commit 87311eb

Please sign in to comment.