memory reorganized into maps and arrays

This commit is contained in:
Luis Fernando Molina committed 2021-08-27 11:18:18 +02:00
1 parent 658bfd2b0d
commit 104499ab57
9 files changed
+45 -41

No files matched your search

+12 -8
View File
@@ -2,13 +2,17 @@
global.NT = {
memory: {
USER_PROFILES_BY_ID: new Map(), // Here we will store the user profiles by User Profile Id.
USER_PROFILES_BY_HANDLE: new Map(), // Here we will store the user profiles by User Profile Handle.
POSTS: new Map(), // This are all the posts we are keeping track of.
EVENTS: new Map(), // This is the registry of all events received that prevents processing them more than once.
TIMELINE: [], // A time ordered list of Posts and Trades.
NETWORK_CLIENTS: [], // These are the Network Clients connected to this Network Node.
NETWORK_PEERS: [], // These are the Network Peers connected to this Network Node.
maps: {
USER_PROFILES_BY_ID: new Map(), // Here we will store the user profiles by User Profile Id.
USER_PROFILES_BY_HANDLE: new Map(), // Here we will store the user profiles by User Profile Handle.
POSTS: new Map(), // This are all the posts we are keeping track of.
EVENTS: new Map(), // This is the registry of all events received that prevents processing them more than once.
},
arrays: {
EVENTS: [], // A time ordered list of events.
NETWORK_CLIENTS: [], // These are the Network Clients connected to this Network Node ordered by Ranking.
NETWORK_PEERS: [], // These are the Network Peers connected to this Network Node ordered by Ranking.
}
},
modules: {
USER_PROFILE: require('./UserProfile.js'),
@@ -19,6 +23,6 @@ global.NT = {
QUERY_PROFILE_STATS: require('./Queries/ProfileStats.js'),
QUERY_PROFILE_POSTS: require('./Queries/ProfilePosts.js'),
QUERY_POST_REPLIES: require('./Queries/ProfileReplies.js'),
QUERY_TIMELINE_CHUNK: require('./Queries/TimelineChunk.js')
QUERY_EVENTS: require('./Queries/Events.js')
}
}
+1 -1
View File
@@ -27,7 +27,7 @@ exports.newPostReplies = function newPostReplies() {
/*
Validate Post
*/
thisObject.post = NT.memory.POSTS.get(queryReceived.targetPostHash)
thisObject.post = NT.memory.maps.POSTS.get(queryReceived.targetPostHash)
if (thisObject.post === undefined) {
throw ('Target Post Not Found.')
+5 -5
View File
@@ -28,9 +28,9 @@ exports.newProfilePosts = function newProfilePosts() {
Validate User Profile
*/
if (queryReceived.targetUserProfileId !== undefined) {
thisObject.profile = NT.memory.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId)
thisObject.profile = NT.memory.maps.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId)
} else {
thisObject.profile = NT.memory.USER_PROFILES_BY_HANDLE.get(queryReceived.targetUserProfileHandle)
thisObject.profile = NT.memory.maps.USER_PROFILES_BY_HANDLE.get(queryReceived.targetUserProfileHandle)
}
if (thisObject.profile === undefined) {
@@ -44,7 +44,7 @@ exports.newProfilePosts = function newProfilePosts() {
}
if (queryReceived.initialPostIndex === INITIAL_POST_INDEX_LAST) {
queryReceived.initialPostIndex = thisObject.profile.posts.length - 1
queryReceived.initialPostIndex = thisObject.profile.maps.POSTS.length - 1
}
if (queryReceived.initialPostIndex === INITIAL_POST_INDEX_FIRST) {
@@ -94,14 +94,14 @@ exports.newProfilePosts = function newProfilePosts() {
switch (thisObject.direction) {
case DIRECTION_FUTURE: {
for (let i = thisObject.initialPostIndex; i < thisObject.initialPostIndex + thisObject.amountRequested; i++) {
let post = thisObject.profile.posts[i]
let post = thisObject.profile.maps.POSTS[i]
if (post === undefined) { break }
addPostToResponse(post)
}
}
case DIRECTION_PAST: {
for (let i = thisObject.initialPostIndex; i > thisObject.initialPostIndex - thisObject.amountRequested; i--) {
let post = thisObject.profile.posts[i]
let post = thisObject.profile.maps.POSTS[i]
if (post === undefined) { break }
addPostToResponse(post)
}
+3 -3
View File
@@ -18,9 +18,9 @@ exports.newProfileStats = function newProfileStats() {
Validate User Profile
*/
if (queryReceived.targetUserProfileId !== undefined) {
thisObject.profile = NT.memory.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId)
thisObject.profile = NT.memory.maps.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId)
} else {
thisObject.profile = NT.memory.USER_PROFILES_BY_HANDLE.get(queryReceived.targetUserProfileHandle)
thisObject.profile = NT.memory.maps.USER_PROFILES_BY_HANDLE.get(queryReceived.targetUserProfileHandle)
}
if (thisObject.profile === undefined) {
@@ -42,7 +42,7 @@ exports.newProfileStats = function newProfileStats() {
"tradePostsFollowersCount": thisObject.profile.tradePostsFollowersCount,
"emitterEventsCount": thisObject.profile.emitterEventsCount,
"targetEventsCount": thisObject.profile.targetEventsCount,
"postsCount": thisObject.profile.postsCount,
"postsCount": thisObject.profile.maps.POSTSCount,
"botsCount": thisObject.profile.botsCount
}
}
+3 -3
View File
@@ -13,7 +13,7 @@ exports.newQuery = function newQuery() {
PROFILE_STATS: 0,
PROFILE_POSTS: 1,
POST_REPLIES: 2,
TIMELINE_CHUNK: 3
EVENTS: 3
}
@@ -48,8 +48,8 @@ exports.newQuery = function newQuery() {
break
}
case QUERY_TYPES.TIMELINE_CHUNK: {
thisObject.query = NT.modules.QUERY_TIMELINE_CHUNK.newTimelineChunk()
case QUERY_TYPES.maps.EVENTS: {
thisObject.query = NT.modules.QUERY_EVENTS.newEvents()
query.initialize(queryReceived)
break
}
+2 -2
View File
@@ -36,13 +36,13 @@ exports.newClientInterface = function newClientInterface() {
*/
let eventReceived = JSON.parse(eventMessage)
if (NT.memory.EVENTS.get(eventReceived.eventId) !== undefined) {
if (NT.memory.maps.EVENTS.get(eventReceived.eventId) !== undefined) {
throw ('Event Already Exists.')
}
let event = NT.modules.EVENT.newEvent()
event.initialize(eventReceived)
NT.memory.EVENTS.set(eventReceived.eventId, event)
NT.memory.maps.EVENTS.set(eventReceived.eventId, event)
}
function queryReceived(queryMessage) {
+4 -4
View File
@@ -58,13 +58,13 @@ exports.newEvent = function newEvent() {
function initialize(eventReceived) {
thisObject.emitterUserProfile = NT.memory.USER_PROFILES_BY_ID.get(eventReceived.emitterUserProfileId)
thisObject.emitterUserProfile = NT.memory.maps.USER_PROFILES_BY_ID.get(eventReceived.emitterUserProfileId)
if (thisObject.emitterUserProfile === undefined) {
throw ('Emitter User Profile Not Found.')
}
thisObject.emitterUserProfile.emitterEventsCount++
thisObject.targetUserProfile = NT.memory.USER_PROFILES_BY_ID.get(eventReceived.targetUserProfileId)
thisObject.targetUserProfile = NT.memory.maps.USER_PROFILES_BY_ID.get(eventReceived.targetUserProfileId)
if (thisObject.targetUserProfile === undefined) {
/* We thow an exception when it does not have a target user profile and is required*/
if (
@@ -172,7 +172,7 @@ exports.newEvent = function newEvent() {
eventReceived.eventType === EVENT_TYPES.ADD_REACTION_ANGRY ||
eventReceived.eventType === EVENT_TYPES.ADD_REACTION_HUG
) {
let targetPost = NT.memory.POSTS.get(eventReceived.targetPostHash)
let targetPost = NT.memory.maps.POSTS.get(eventReceived.targetPostHash)
if (targetPost === undefined) {
throw ('Target Post Not Found')
@@ -190,7 +190,7 @@ exports.newEvent = function newEvent() {
eventReceived.eventType === EVENT_TYPES.REMOVE_REACTION_ANGRY ||
eventReceived.eventType === EVENT_TYPES.REMOVE_REACTION_HUG
) {
let targetPost = NT.memory.POSTS.get(eventReceived.targetPostHash)
let targetPost = NT.memory.maps.POSTS.get(eventReceived.targetPostHash)
if (targetPost === undefined) {
throw ('Target Post Not Found')
+1 -1
View File
@@ -86,7 +86,7 @@ exports.newPost = function newPost() {
event.eventType === POST_TYPES.RE_POST_TRADE ||
event.eventType === POST_TYPES.QUOTE_REPOST_TRADE
) {
thisObject.targetPost = NT.memory.POSTS.get(thisObject.targetPostHash)
thisObject.targetPost = NT.memory.maps.POSTS.get(thisObject.targetPostHash)
if (thisObject.targetPost === undefined) {
throw ('Target Post Not Found.')
+14 -14
View File
@@ -46,7 +46,7 @@ exports.newUserProfile = function newUserProfile() {
thisObject.tradePostsFollowing = undefined
thisObject.tradePostsFollowers = undefined
thisObject.posts = undefined
thisObject.maps.POSTS = undefined
thisObject.bots = undefined
}
@@ -64,10 +64,10 @@ exports.newUserProfile = function newUserProfile() {
thisObject.tradePostsFollowersCount = 0
thisObject.emitterEventsCount = 0
thisObject.targetEventsCount = 0
thisObject.postsCount = 0
thisObject.maps.POSTSCount = 0
thisObject.botsCount = 0
thisObject.posts = []
thisObject.maps.POSTS = []
thisObject.bots = undefined
}
@@ -78,7 +78,7 @@ exports.newUserProfile = function newUserProfile() {
userProfile,
timestamp
) {
if (NT.memory.POSTS.get(emitterPostHash) !== undefined) {
if (NT.memory.maps.POSTS.get(emitterPostHash) !== undefined) {
throw ('Post Already Exists.')
}
@@ -91,29 +91,29 @@ exports.newUserProfile = function newUserProfile() {
timestamp
)
thisObject.posts.push(post)
NT.memory.POSTS.set(emitterPostHash, post)
thisObject.postsCount++
thisObject.maps.POSTS.push(post)
NT.memory.maps.POSTS.set(emitterPostHash, post)
thisObject.maps.POSTSCount++
}
function removePost(
emitterPostHash
) {
if (NT.memory.POSTS.get(emitterPostHash) === undefined) {
if (NT.memory.maps.POSTS.get(emitterPostHash) === undefined) {
throw ('Post Does Not Exist.')
}
let post = thisObject.posts.get(emitterPostHash)
let post = thisObject.maps.POSTS.get(emitterPostHash)
post.finalize()
for (let i = thisObject.posts.length - 1; i >= 0; i-- {
if (thisObject.posts[i].emitterPostHash === emitterPostHash) {
thisObject.posts.splice(i, 1)
for (let i = thisObject.maps.POSTS.length - 1; i >= 0; i--) {
if (thisObject.maps.POSTS[i].emitterPostHash === emitterPostHash) {
thisObject.maps.POSTS.splice(i, 1)
break
}
}
NT.memory.POSTS.delete(emitterPostHash)
thisObject.postsCount--
NT.memory.maps.POSTS.delete(emitterPostHash)
thisObject.maps.POSTSCount--
}
function addMultiMediaPostsFollowing(