orientdb - Implementing an infinite scroll news feed graph model -


i building social networking kind of website. using python , orientdb. trying fetch posts of users (user2, user3, user4, etc) connected user1 , show posts in news feed of user1.

for this, using graphity model retrieve top 'k' news feed efficiently. but, challenge comes in when, example users scrolls down , top 'k' feeds shown him already. want fetch 'k' left off, ie. 'k+1', 'k+2', etc. right or efficient way this?

i can think of retrieving top '2k' news feed again, , when that's consumed, retrieve top '3k' feeds , on. but, can see, heavy that.

is there predefined solution problem or solution can think of, can continue fetching posts left, once top 'k' feeds retrieved first.

i recommend use linkmap if wish store mixed values. more efficient cause won't have traverse through whole list. experimenting, found can expand array of keys , it's efficient !

here how syntax looks :

select expand(feed[3-5]) <#user:id> 

for infinite scroll, can build query in server side function selects items @ positions want :-) if keys represent positions in map, can position of last element in map , use fetch last x elements.

the squared brackets allow :

  • filtering 1 index, example out()[0]
  • filtering multiple indexes, example out()[0,2,4]
  • filtering ranges, example out()[0-9]

here exemple, using orientgraph in orientdb function :

fetching mecanism

first, last key value command :

var lastkey = db.command("sql","select last(feed.keys()) lastkey <#user:id>")[0].getrecord().tomap()["lastkey"];` 

second, execute query keys want :

return db.command("sql","select expand(feed[" + (parseint(lastkey) -20).tostring() + "-" +  lastkey + "]) <#user:id>"); 

insert mechanism

first, last key value :

var lastkey = db.command("sql","select last(feed.keys()) lastkey <#user:id>")[0].getrecord().tomap()["lastkey"];` 

second, put new element @ last key value incremented 1 :

db.command("sql","update <user-id> put feed = \""(parseint(lastkey) + 1).tostring()"\", <#newelem:id> 

hope solution.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -