Saving the user activity in the database(sql)

Asked

Viewed 45 times

1

I am creating a chart to analyze the access of posts by age group by time on my site. But the site does not yet have this ability to capture the activity of the user and need to do it.

My task and change the database to make this possible, currently I have the following tables:

table user{
    id_user (Chave Primaria);
    date_of_birth (date);
    name (char(255))
}

table post{
    id_post (Chave Primaria);
    title (char(255))
}

When a user 'Tobias' access the posts 'How to bake an egg' on '23 May 2018' at '13:31' for '30 seconds', I will need to have this information in the database.

First I thought about creating a table in the most intuitive way possible:

table acesso{
    id_acesso(Chave primaria);
    id_user (Chave estrangeira);
    id_post(Chave estrangeira);
    date (timestamp);
    duration (inteiro, segundos);
}

But I don’t know what is the most efficient way to do this table or if there is a better form or if I’m doing the right thing. Because I’m planning this bank to have thousands of users and posts, and efficiency is something desired.

  • 2

    First of all, wouldn’t Google tools help you in this quest? In this case, Analytics?

  • 1

    I thought about this possibility, but currently I will have to make my own Analytics, I am making a chart on D3 and I will use the information I will acquire to create my own charts.

  • 1

    This way, will only record the data of users who have some kind of registration in your system.

  • 2

    In this case, keep in mind that the more information the better! Also know, you will not always have the information you need. I ask: Wouldn’t the geographic position of the user be interesting to you? If so, it would be nice to put latitude and longitude on that basis. I would also recommend a non-relational structure. Maybe a mongodb. Reason: You will have a lot of information on that basis. With this type of database you will have more performance in your queries and a more coherent data organization.

  • 1

    You can also use the type jsonb of postgres to store this information. If I’m not mistaken from 9.4 it already has indexes support inclusive. I also remember seeing an article disclosing that the performance of postgres with jsonb was better than that of mongodb, but I could not locate the link.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.