Frage

I'm building a simple graph and I want to ask your suggestions on how to do it so that when it gets more vertices and edges added, it will still perform pretty well. The layout of my graph is like this.

user --> follows --> user (userVertex)
user --> generates --> activity (activityVertex)

this is my query:

select
from (
 select
 flatten(out[label='generates'].in)
 from (
  select
  flatten(out[label='follows'].in)
  from #6:0
 )
)
where @class = 'activityVertex'
order by id desc
limit 20

and when i do pagination (e.g. show more activities), i just add this on the where clause:

where @class = 'activityVertex'
and id < 1234
limit 20

where 1234 above is the id of the last activity being displayed.

this is working all fine when a person follows like < 10 users and each user has like < 500 activities. but when it grows bigger than that, it put such a strain on the order by clause ordering all the activities by date to present the activity stream to the user.

i wonder how twitter does it? are there some design principles, even the ones that aren't strictly OrientDB-related, that i have yet to apply which will make this possible?

War es hilfreich?

Lösung

You could use the SKIP keyword. SKIP+LIMIT do the magic:

SELECT ... SKIP 0  LIMIT 20  // 1st page
SELECT ... SKIP 20 LIMIT 20 // 2st page
SELECT ... SKIP 40 LIMIT 20 // 2st page
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top