訪問履歴の連続を復元できますか?

Hello,

Recently my forum had an extended 2 day downtime because of issues with our domain.

That caused everybody’s visit streaks to break, which is very bad to most people.

I’m looking to restore these, how can I?

「いいね!」 1

You’d need to contrive to add data to the tables to make it look like everyone visited on those days. You’d need to read the source, figure out which tables need to add rows to, and then create records on them for each user.

If you don’t know how to do that and do not get a response quickly enough, you can post a budget in marketplace.

「いいね!」 2

They need to get their priorities straight :wink:

Anyway, to copy visits from one day to another you need to run this SQL query

insert into user_visits
  select 0, user_id, '2022-09-09', posts_read, mobile, 0 
  from user_visits 
  where visited_at = '2022-09-08'
;

where the first date is the date you want to fake and the second date is where you want to copy from.

「いいね!」 7

Richard saves the day again! What a great solution. I was wondering how to do it without just giving everyone credit. Brilliant!

「いいね!」 5

You would be shocked the amount of people that complained about it :face_with_diagonal_mouth:

Thanks for the script, where can I run it?

「いいね!」 2
cd /var/discourse
./launcher enter app
rails c
DB.exec("insert into user_visits select 0, user_id, '2022-09-09', posts_read, mobile, 0 from user_visits where visited_at = '2022-09-08'")
「いいね!」 4

Hey, we had another outage, and when I went to restore the visits again, we had an error.

[6] pry(main)> DB.exec("insert into user_visits select 4, user_id, '2022-12-31', posts_read, mobile, 0  from user_visits where visited_at = '2022-09-01'")
PG::UniqueViolation: ERROR:  duplicate key value violates unique constraint "user_visits_pkey"
DETAIL:  Key (id)=(4) already exists.

from /var/www/discourse/vendor/bundle/ruby/3.1.0/gems/rack-mini-profiler-3.0.0/lib/patches/db/pg.rb:110:in `exec'