Jump to the post that solved this thread.
Solved: 4 Years, 10 Months, 3 Weeks ago How the mybb_threadsread SQL table works
#11
Solved: 4 Years, 10 Months, 3 Weeks ago
It's slightly confusing you are talking about 2 different tables that have totally different purpose. However your code simply doesn't work without additional changes.
a) By mybb_threadsviews has just one column. There is no way to find views from the same user.
b) It doesn't change how views are counted at all (beside potentially counting the same views multiple times)
c) Your query will throw a SQL error. TRUNCATE queries don't support WHERE conditions: https://stackoverflow.com/a/8416804
[Image: banner.png]
Reply
#12
Solved: 4 Years, 10 Months, 3 Weeks ago
(2020-03-05, 02:20 PM)StefanT Wrote: It's slightly confusing you are talking about 2 different tables that have totally different purpose. However your code simply doesn't work without additional changes.
a) By mybb_threadsviews has just one column. There is no way to find views from the same user.
b) It doesn't change how views are counted at all (beside potentially counting the same views multiple times)
c) Your query will throw a SQL error. TRUNCATE queries don't support WHERE conditions: https://stackoverflow.com/a/8416804

Obviously you are still wrong and talking about something else, since you have still not understood the initial problem and the solution.

The previous explanation is clear. Before being critical, make sure you understand the initial problem Lightbulb .

My problem being solved, I would no longer answer. I'm sure you want the last word so I'll leave it to you.

Best regards
Reply
#13
Solved: 4 Years, 10 Months, 3 Weeks ago
Why exactly did you change your code to fix that TRUNCATE query then? It still doesn't work btw, because there is no dateline column on that table.
[Image: banner.png]
Reply
#14
Solved: 4 Years, 10 Months, 3 Weeks ago
[Image: ead87ffe345bcc5a814afec60487adf2.gif]
Reply
#15
Solved: 4 Years, 10 Months, 3 Weeks ago
(2020-03-05, 05:43 PM)StefanT Wrote: Why exactly did you change your code to fix that TRUNCATE query then? It still doesn't work btw, because there is no dateline column on that table.

He specifically suggests to add such line, if I'm not mistaken.

But, I'm quite confused myself about the problem and solution provided (solution mostly because I haven't checked the code yet because I'm confused about the problem itself).

@Nik83, are you trying to stop thread view count increasing infinity times when threads are viewed by the same user? If so, are you trying to limit the amount of thread view count increases by the same user to up to 2 per year?

If I understand the issue then I understand you trying to fixing it because I have always consider that a hassle myself.
Soporte en Español

[Image: signature.png]

Discord at omar.gonzalez (Omar G.#6117); Telegram at @omarugc;
Reply
#16
Solved: 4 Years, 10 Months, 3 Weeks ago
(2020-03-05, 09:10 PM).Omar G. Wrote: @Nik83, are you trying to stop thread view count increasing infinity times when threads are viewed by the same user? If so, are you trying to limit the amount of thread view count increases by the same user to up to 2 per year?
 
Yes

But the only reliable solution is problematic, because it is necessary to create a permanent table which stores all the identifiers of the users consulting a discussion, but this table can become too large and slow down the forum in the long term.

So the solution here is an intermediate solution. We limit the number of views using a semi-permanent table

This code, I wrote it directly during my first edition of my answer (a draft), I update it with the code that I use in production.

In any case, the accounting system poses a problem, we cannot count several times a subject read by the same user, it does not make sense.
Reply
#17
Solved: 4 Years, 10 Months, 3 Weeks ago
(2020-03-05, 09:10 PM)Omar G. Wrote: He specifically suggests to add such line, if I'm not mistaken.
Well, when I posted, it said there were no changes to the database structure. I still think his posts is missing crucial information and important parts of code.

I recommend not to modify mybb_threadviews table though. Why not simply query mybb_threadsread? That would be just a few lines of code in showthread.php:
	if($mybb->user['uid'])
	{
		$query = $db->simple_select("threadsread", "dateline", "uid='{$mybb->user['uid']}' AND tid='{$thread['tid']}'");
		$threadread = $db->fetch_field($query, "dateline");
	}
	else
	{
		$threadread = (int)my_get_array_cookie("threadread", $thread['tid'])
	}

	if(!$threadread)
	{
		// Increment the thread view.
		if($mybb->settings['delayedthreadviews'] == 1)
		{
			$db->shutdown_query("INSERT INTO ".TABLE_PREFIX."threadviews (tid) VALUES('{$tid}')");
		}
		else
		{
			$db->shutdown_query("UPDATE ".TABLE_PREFIX."threads SET views=views+1 WHERE tid='{$tid}'");
		}
		++$thread['views'];
	}
[Image: banner.png]
Reply
Jump to the post that solved this thread.


Forum Jump:


Users browsing this thread: