-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
78 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
import cypher, {escape} from '../utils/DB_connection.js'; | ||
import cypher, {escape} from '../utils/graph_connection.js'; | ||
import {addTask} from '../utils/task_queue.js'; | ||
import callVK from '../utils/VK_stack_caller.js'; | ||
|
||
//noinspection JSUnusedGlobalSymbols | ||
export default async function reflexGroupsFromQuery(query) { | ||
let {items: groups} = await callVK('groups.search', {q: query, type: 'page', count: 1000}); | ||
console.log(groups); | ||
if (Array.isArray(groups)) | ||
for (let group of groups) | ||
await cypher(` | ||
MERGE (g:VK_Group { id: ${group.id} }) | ||
ON CREATE SET g.created = timestamp() | ||
MERGE (user_task:Task {type: 'reflexUsers', data: ${group.id} }) | ||
ON CREATE SET user_task.ts = 0 | ||
MERGE (track_task:Task {type: 'reflexTracks', data: ${group.id} }) | ||
ON CREATE SET track_task.ts = 0 | ||
`); | ||
await cypher( | ||
`FOREACH (id in {ids} | MERGE (group:VK_Group {id: id}))`, | ||
{ids: groups.map(group => group.id)} | ||
); | ||
for (let group of groups) { | ||
addTask(['reflexUsers', group.id]); | ||
addTask(['reflexTracks', group.id]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* Important notice: all this stuff is expected to improve performance on graph operations | ||
* Previously tasks were also stored in Neo4j, but I've encountered significant lack of speed | ||
* */ | ||
|
||
import Redis from 'ioredis'; | ||
const db = new Redis(process.env.REDIS_HOST); | ||
|
||
const taskPresenceKey = 'graph_dump:tasks:presenceHash'; | ||
const taskOrderKey = 'graph_dump:tasks:presenceList'; | ||
|
||
export async function addTask(taskData){ | ||
if (taskData instanceof Object) { | ||
var taskString = JSON.stringify(taskData); | ||
var exists = await db.hsetnx(taskPresenceKey, taskString, 1); | ||
if (!exists) { | ||
await db.rpush(taskOrderKey, taskString); | ||
} | ||
} else { | ||
throw new TypeError; | ||
} | ||
} | ||
|
||
export async function getTask(){ | ||
var task = await db.rpoplpush(taskOrderKey, taskOrderKey); | ||
return JSON.parse(task); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters