[erlang-questions] What's the best way to select articles by page in a forum?

Liu Yubao yubao.liu@REDACTED
Mon Jan 12 10:54:58 CET 2009


Hi,

I'm trying to implement a web forum with Erlang + Mnesia and meet a big difficult
problem. This is the record to represent an article:

  -record(article, {id, parent_id, topic_id, author, title, content, timestamp}).

For a new article:
    id = md5(author + title + timestamp).
    parent_id = <<0>>.
    topic_id = id.

For a reply:
    parent_id = parent's id.
    topic_id = parent's topic_id.
    id = md5(parent_id + topic_id + author + title + timestamp).

I use md5 digests instead of monotone increasing integers as id because I hope
there is no centralized counter that is bad for concurrency and distribution.

Now the problem is how I select [N, N + 20) topics efficiently and how I select
[N, N + 20) articles in a topic efficiently.

In SQL I can do like this:

	SELECT * FROM article WHERE id = topic_id ORDER BY timestamp
        SELECT * FROM article WHERE topic_id = ? ORDER BY timestamp

and then read the result *one by one*, but it seems mnesia doesn't support this
traverse, it only support two kinds of traverse:

   * traverse whole table
     (not efficient)
   * get the whole result set immediately and traverse records in it
    (consume many memory)

Any suggestion is appreciated!


Best regards,

Liu Yubao




More information about the erlang-questions mailing list