Skip to content

Commit

Permalink
Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
anudit committed Apr 25, 2022
1 parent aa916e8 commit 8e6211e
Show file tree
Hide file tree
Showing 4 changed files with 388 additions and 432 deletions.
1 change: 1 addition & 0 deletions .slugignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.next/cache
72 changes: 38 additions & 34 deletions cron/cacheV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,16 @@ function avg(array) {
return total / count;
}

async function cacheTrustScoresManual(addresses){
function cleanNulls(obj){
return JSON.parse(JSON.stringify(obj), (key, value) => {
if (value == null)
return undefined;
return value;
});

}

async function cacheTrustScoresManual(addresses, mongoClient){

const price_data = await fetcher('https://api.covalenthq.com/v1/pricing/tickers/?tickers=ETH,MATIC&key=ckey_2000734ae6334c75b8b44b1466e', "GET", {});
const GLOBAL_ETH_PRICE = parseFloat(price_data['data']['items'][0]['quote_rate']);
Expand All @@ -230,20 +239,21 @@ async function cacheTrustScoresManual(addresses){

console.log('Iterating over', addresses.length);

const client = await MongoClient.connect(MONGODB_URI);
let db = client.db('convo');
let db = mongoClient.db('convo');
let coll = db.collection('cachedTrustScores');

for (let index = 0; index < addresses.length; index++) {
let startDate = new Date();
const lookupAddress = getAddress(addresses[index]);

let scoreData = await computeScoreData(lookupAddress);
scoreData = cleanNulls(scoreData); // Mongo freaks out when it sees a null.

let newDoc = {
_id: getAddress(lookupAddress),
...scoreData
}

await coll.updateOne(
{ _id : getAddress(lookupAddress)},
{ $set: newDoc },
Expand All @@ -257,29 +267,15 @@ async function cacheTrustScoresManual(addresses){
console.log(`🟢 Cached ${index}`, scoreData.score, ` | Avg Time: ${parseFloat(avg(times)).toFixed(3)}s`);
}

client.close();

}

const getAddresses = async (threadClient) =>{

let promise = new Promise((res, rej) => {

MongoClient.connect(MONGODB_URI, async function(err, client) {
if(err) throw err;
let db = client.db('convo');
let coll = db.collection('cachedTrustScores');
const getAddresses = async (threadClient, mongoClient) =>{

const cursor = await coll.distinct("_id", {});
console.log('cursor.length', cursor.length);
res(cursor);

client.close();
let db = mongoClient.db('convo');
let coll = db.collection('cachedTrustScores');

});

});
let snapshot_trustscores = await promise;
const snapshot_trustscores = await coll.distinct("_id", {});
console.log('cursor.length', snapshot_trustscores.length);

const threadId = ThreadID.fromString(TEXTILE_THREADID);
let snapshot_comments = await threadClient.find(threadId, 'comments', {});
Expand Down Expand Up @@ -323,9 +319,12 @@ function getArraySample(arr, sample_size, return_indexes = false) {

async function runPipline(){
const threadClient = await getClient();
const addressTable = await getAddresses(threadClient);
const sampledAddresses = getArraySample(addressTable, 5500);
await cacheTrustScoresManual(sampledAddresses);
const mongoClient = await MongoClient.connect(MONGODB_URI);

let addressTable = await getAddresses(threadClient, mongoClient);
addressTable = getArraySample(addressTable, 5500);
await cacheTrustScoresManual(addressTable, mongoClient);
await mongoClient.close();
}

runPipline().then(()=>{
Expand All @@ -340,12 +339,17 @@ runPipline().then(()=>{
// }
// cacheAddsFromFile("toindex.json");

// cacheTrustScoresManual([
// // "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
// // "0xcf0949bf6d2adf8032260fd08039c879cf71c128",
// // "0xD665afb9A4019a8c482352aaa862567257Ed62CF",
// // "0xB53b0255895c4F9E3a185E484e5B674bCCfbc076",
// // "0xa28992A6744e36f398DFe1b9407474e1D7A3066b",
// // "0x707aC3937A9B31C225D8C240F5917Be97cab9F20",
// // "0xa28992A6744e36f398DFe1b9407474e1D7A3066b"
// ])
// async function runPipline2(){
// const mongoClient = await MongoClient.connect(MONGODB_URI);
// await cacheTrustScoresManual([
// "0x707aC3937A9B31C225D8C240F5917Be97cab9F20",
// // "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
// // "0xcf0949bf6d2adf8032260fd08039c879cf71c128",
// // "0xD665afb9A4019a8c482352aaa862567257Ed62CF",
// // "0xB53b0255895c4F9E3a185E484e5B674bCCfbc076",
// // "0xa28992A6744e36f398DFe1b9407474e1D7A3066b",
// // "0xa28992A6744e36f398DFe1b9407474e1D7A3066b"
// ], mongoClient);
// await mongoClient.close();
// }
// runPipline2();
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,21 @@
"@oceanprotocol/lib": "^0.20.2",
"@onflow/fcl": "^0.0.78",
"@portis/web3": "^4.0.7",
"@react-three/drei": "^9.5.2",
"@react-three/drei": "^9.5.3",
"@react-three/fiber": "^8.0.12",
"@self.id/web": "^0.3.0",
"@self.id/web": "^0.4.0",
"@solana/web3.js": "^1.39.1",
"@textile/hub": "^6.3.4",
"@theconvospace/sdk": "^0.4.2",
"@uauth/js": "^1.0.0",
"@uauth/web3modal": "^1.0.0",
"@theconvospace/sdk": "^0.4.3",
"@uauth/js": "^1.1.0",
"@uauth/web3modal": "^1.1.0",
"@walletconnect/web3-provider": "^1.7.7",
"ably": "^1.2.20",
"bson-ext": "^4.0.2",
"critters": "^0.0.16",
"dotenv": "^15.0.0",
"ethers": "^5.6.4",
"framer-motion": "^6.3.0",
"framer-motion": "^6.3.1",
"ioredis": "^5.0.4",
"js-cookie": "^3.0.1",
"jsonwebtoken": "^8.5.1",
Expand Down Expand Up @@ -88,7 +88,7 @@
},
"devDependencies": {
"@next/eslint-plugin-next": "^12.1.5",
"eslint": "^8.13.0",
"eslint": "^8.14.0",
"eslint-config-next": "^12.1.5",
"eslint-plugin-react": "^7.29.4",
"eslint-plugin-react-hooks": "^4.4.0",
Expand Down
Loading

1 comment on commit 8e6211e

@vercel
Copy link

@vercel vercel bot commented on 8e6211e Apr 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

convo – ./

convo-convo.vercel.app
convo-sooty.vercel.app
convo-git-main-convo.vercel.app

Please sign in to comment.