D
D
dzoid2017-06-10 00:03:50
PHP
dzoid, 2017-06-10 00:03:50

How to store subscriptions to tags (categories) and pull them out?

Good afternoon, on the social news site, there is a table of news like
id, title, categories, tags
12, title, ',24,11', ',88,125,'
13, title2, ',34', ',28,154,241,'
I want to add functionality so that the user can subscribe to updates from a specific news category or news tag, at the moment it works like this:

SELECT * FROM `posts` WHERE `tags` LIKE ',1400,' OR `tags` LIKE ',1309,' OR `categories` LIKE ',11,' и т д

User subscriptions are stored in a table of the form
userid, tag_id, category_id
1, 23,
1, , 199
After the request, the result is stored in the file cache, which is considered relevant for 12 hours, when the user clicks on the subscribe or unsubscribe button - his cache is deleted, how can I increase the performance of this functionality?
I would also like to update the user's cache when a news of a suitable category is released, what is the best way to do this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
ipokos, 2017-06-10
@ipokos

I can assume that subscriptions are used to display news to which the user has subscribed.
Then you have a table with categories:
id_cat. | name_cat.
1 | example_name_1
2 | example_name_2
...
And the user table as
id_user | name | etc ... | categories
Marked categories by the user can be added to an array, serialized, written as a string.
When a user logs in, get his id and his marked categories
, anserialize the string into an array and you can compose, for example, a query:
SELECT name, your, columns FROM your_table WHERE id IN (1 , 2 ... or supplement the query to select first by tags or t .p.)
In general, this is an option.
Why are you storing user subscriptions in a file cache?
Wouldn't it be better then not to load the server and the database with tables, if the user can only have temporary subscriptions and store them in cookies, for example?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question