I have type called Profile, with some fields like name, etc…
I need to give some basic statistics of the Profile number of views, like:
Views in the last 7 days
Views in the last 30 days
etc…
I was thinking of creating a Type called View with only one field, Profile (type Profile).
And every time a profile page is loaded, create 1 entry of View.
But if I do this, the database can get pretty huge in a couple of months.
I have also the option to just create a field in Profile, views (type number), and every profile page load, add a +1. But I don´t know if by going this way, I would be capable to have the statistics I need.
I don’t think so, to get this kind of information you will probably have to create a new type with the number of views and the date of each view, and so it will take up a lot of database space, or you can try using the Google Analytics API
One thing you could do is store the views as a separate data type, as you proposed, AND store a number field on the profile object for each stat you want to capture (Views in last 7 days, 30 days etc).
Then schedule a recursive workflow to run every few hours or every day, which cycles through every profile, counting up the views for each and saving it to the corresponding field on the profile object.
Your users won’t see the load speed be affected and the only thing to watch out for is the number of profiles you have the system, though it’s a pretty simple operation, couldn’t imagine it being that impactful on the server if you space out the backend workflows.
The thing is that in the future, I would like not only to have a static last 30 days statistic, I would love having the ability to filter. For example, show me the views of the last 9 days or 33 days, etc…
@hacker I wouldn’t worry about it too much. Bubble should load the stats you need pretty quickly even with 1000s of views, so long as you don’t do any client-side filtering (i.e. do everything through the do a search for expression.
Also, it may not be relevant anyway, but if you’re on the professional plan you can use database triggers instead of my suggestion above. Every time you create a view object you have a database trigger fire which increments the relevant number fields by one.