[erlang-questions] Efficient way to store message lists in mnesia

Aleksander Nycz Aleksander.Nycz@REDACTED
Tue Jun 7 21:32:14 CEST 2016


Hello,

Try this:

Users table:

{userId, firstMessageId, lastMessageId}

Messages table:

{MessageId, prevMessageId, nextMessageId, Message}


Insert 1st message for user 1000:

Users table:

{1000, 1, 1}

Message table:

{1, undefined, undefined, "message1"}


Insert 2nd message for user 1000:

Users table:

{1000, 1, 2}

Message table:

{1, undefined, 2, "message1"}

{2, 1, undefined, "message2"}

And so on...

You can also agregate messages (yearly/monthly/daily):

{{UserId, Year}, firstMessageId, lastMessageId}


Regards

Aleksander


W dniu 2016-06-03 o 19:08, Khitai Pang pisze:
> Hi,
>
> I need to store a list of unread messages for every user id.  The order
> of the messages needs to be preserved.  Currently I store the messages
> in a list as the value of the user id key in a table of type set:
>
> {user_id, [message]}
>
> The table is a disc_copies table.
>
> Whenever someone sends a message to a user, the message is prepended to
> the head of the message list of the user.
>
> Now my concern is, adding a new message to the list requires reading and
> writing the whole list, which can be pretty slow if the list is very
> long, i.e. thousands of messages.
>
> There is another way to do this, which uses a table of type bag and
> composite keys:
>
> {user_id, timestamp1, message1}
> {user_id, timestamp2, message2}
> {user_id, timestamp3, message3}
> ...
>
> But I don't think this is any better because I heard that mnesia bag
> tables performance is very bad:
> http://erlang.org/pipermail/erlang-questions/2011-March/057044.html
>
> Are there other ways to store lists of messages in mnesia where
> reading/updating the message lists can be very efficient?
>
>
> -Khitai
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4936 bytes
Desc: Kryptograficzna sygnatura S/MIME
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20160607/38301b35/attachment.bin>


More information about the erlang-questions mailing list