qbittorrent / qBittorrent

qBittorrent BitTorrent client
https://www.qbittorrent.org
Other
27.48k stars 3.9k forks source link

API last_activity is a future date #12308

Open austinwbest opened 4 years ago

austinwbest commented 4 years ago

qBittorrent version and Operating System

4.2.2 on Windows 10 Pro (10.0.1xxxx)

What is the problem

last_activity is a future date

What is the expected behavior

last_activity to be <= now

Extra info(if any)

Ive dumped out some of the torrents with their relevant data...

"Torrent" = name
"Path" = save_path
"Completed" = completion_on
"Active" = last_activity

Today is 3/27 but yet they have dates for the 30th and even into next month!!

Code being used:

writeDebugData("\t\t".'Torrent: '. $torrent['name'], SYSTEM_DEBUG_FILE, basename(__FILE__), __LINE__);
writeDebugData("\t\t\t".'Path: '. $torrent['save_path'], SYSTEM_DEBUG_FILE, basename(__FILE__), __LINE__);
writeDebugData("\t\t\t".'Completed: '. date('m/d/Y h:i A', $torrent['completion_on']), SYSTEM_DEBUG_FILE, basename(__FILE__), __LINE__);
writeDebugData("\t\t\t".'Active: '. date('m/d/Y h:i A', $torrent['last_activity']), SYSTEM_DEBUG_FILE, basename(__FILE__), __LINE__);

Result:

03/27/20 10:04:47 PM --         Torrent: Legacies.S02E14.iNTERNAL.1080p.WEB.H264-GHOSTS [index.php 420]
03/27/20 10:04:47 PM --             Path: S:\ [index.php 421]
03/27/20 10:04:47 PM --             Completed: 03/16/2020 09:25 PM [index.php 422]
03/27/20 10:04:47 PM --             Active: 04/02/2020 12:20 AM [index.php 423]
03/27/20 10:04:47 PM --         Torrent: NCIS.Los.Angeles.S11E16.720p.HDTV.x264-AVS [index.php 420]
03/27/20 10:04:47 PM --             Path: S:\ [index.php 421]
03/27/20 10:04:47 PM --             Completed: 03/13/2020 08:44 PM [index.php 422]
03/27/20 10:04:47 PM --             Active: 03/27/2020 10:04 PM [index.php 423]
03/27/20 10:04:47 PM --         Torrent: The.Walking.Dead.S10E11.1080p.WEB.H264-XLF [index.php 420]
03/27/20 10:04:47 PM --             Path: S:\ [index.php 421]
03/27/20 10:04:47 PM --             Completed: 03/13/2020 08:34 PM [index.php 422]
03/27/20 10:04:47 PM --             Active: 03/30/2020 03:56 PM [index.php 423]
03/27/20 10:04:47 PM --         Torrent: DCs.Legends.of.Tomorrow.S05E08.720p.HDTV.x264-AVS [index.php 420]
03/27/20 10:04:47 PM --             Path: S:\ [index.php 421]
03/27/20 10:04:47 PM --             Completed: 03/17/2020 10:09 PM [index.php 422]
03/27/20 10:04:47 PM --             Active: 04/01/2020 06:22 AM [index.php 423]
03/27/20 10:04:47 PM --         Torrent: Will.and.Grace.S11E06.720p.HDTV.x264-AVS [index.php 420]
03/27/20 10:04:47 PM --             Path: S:\ [index.php 421]
03/27/20 10:04:47 PM --             Completed: 03/12/2020 11:27 PM [index.php 422]
03/27/20 10:04:47 PM --             Active: 03/30/2020 11:13 PM [index.php 423]
03/27/20 10:04:47 PM --         Torrent: DCs.Legends.of.Tomorrow.S05E07.1080p.WEB.H264-XLF [index.php 420]
03/27/20 10:04:47 PM --             Path: S:\ [index.php 421]
03/27/20 10:04:47 PM --             Completed: 03/13/2020 10:08 PM [index.php 422]
03/27/20 10:04:47 PM --             Active: 04/01/2020 06:11 AM [index.php 423]

** Sidenote, just turned on the "Last Activity" column and it shows the infinity sign for a majority of everything. Fair to say this column simply is useless at this point in time?

FranciscoPombal commented 4 years ago

Probably related: https://github.com/qbittorrent/qBittorrent/issues/11685 https://github.com/qbittorrent/qBittorrent/issues/11593

austinwbest commented 4 years ago

Maybe indirectly.. These have dates, not a 0 or - 1. These are also not old, 2 weeks at most is when I switched from deluge to qbit. That is why I opened a new one instead of appending the others.

FranciscoPombal commented 4 years ago

Maybe indirectly.. These have dates, not a 0 or - 1. These are also not old, 2 weeks at most is when I switched from deluge to qbit. That is why I opened a new one instead of appending the others.

Yes, I'm not saying it's a duplicate, because I'm not 100% sure either.

austinwbest commented 4 years ago

Something else i have noticed, that column doesn't update in realtime like others do. You have to change views to trigger a reload for the column to update. My highest was 4 hrs 59 mins and when i switched from All to Active and back to All now i have some that are more than 1 day. Not sure if that is expected/intentional but just informing since i noticed it while looking at that specific column.

I'll try to get some time to clone/build from source and see if i can track down the issue to possibly help out. I assume it builds/works with VS19? That is what i use for Sonarr anyways so hopefully so.

FranciscoPombal commented 4 years ago

I'll try to get some time to clone/build from source and see if i can track down the issue to possibly help out. I assume it builds/works with VS19? That is what i use for Sonarr anyways so hopefully so.

This is the method use for official releases (works with VS 2019 also). It is quite a lengthy process though. @xavier2k6 can probably help you if you have problems. https://github.com/qbittorrent/qBittorrent/wiki/Compiling-with-MSVC-2017-%28static-linkage%29

austinwbest commented 4 years ago

Worse case I might be able to track it down with out building it. Just not test lol

xavier2k6 commented 4 years ago

@austinwbest give me a shout if you run in to trouble compiling yourself, I compile with VS2019 too for x64.

Just a quick question, what BUILD of windows 10 are you running?

austinwbest commented 4 years ago

Just a quick question, what BUILD of windows 10 are you running?

@xavier2k6 the computer i would use for this is Version 1809 Build 17763.1098

I have a few computers i could use (2 win 10's and a win 7 but also have a couple linux boxes (debian & ubuntu) if need be). As a web developer i kinda have shit everywhere lol

austinwbest commented 4 years ago

I would like to sort this out as i have a lot of automation and one trigger is based on activity. Deluge didn't have it at all so i built a system around the API using the peers system to keep track of activity but in the end the API is much better with qBit so i made the switch. Just need a stable activity mechanism and everything else i think is spot on for everything i do with it.

xavier2k6 commented 4 years ago

What I meant was what is the OS version/build you are currently experiencing this issue on.....is it the 1809 build you mentioned?

austinwbest commented 4 years ago

Yes, the one mentioned is the one i currently have qBit installed on

xavier2k6 commented 4 years ago

is your original post the official build or self-compiled too?

Have a look at the wiki instructions anyway & see how you get on..... get the (latest vsaddin 2.4.3) Qt VS Tools for Visual Studio 2019

austinwbest commented 4 years ago

So far i have not touched anything, it is the released build.

Edit: I actually just got home so i was going to go ahead and clone the repo and see whats what

xavier2k6 commented 4 years ago

ok, let me know if you get stuck anywhere in the compilation instructions.

austinwbest commented 4 years ago

Ok, so i guess i need some clarification here on what exactly is desired for the last activity..

I would assume it is the timestamp for when it was last uploaded/downloaded however that is not consistent across the code. It appears it can be a -1, 0 or timestamp so there is no way this will ever work right in that scenario.

It seems it is being treated as 2 results in one:

Can/should it not simply update with the current timestamp when it is being uploaded/downloaded and that is all the field is used for? Everything else can do the math based on timestamps accordingly instead of trying to purpose the same field for multiple results. Maybe i am missing something as i have only done a prelim look at this code.

The field should never be anything other than a timestamp, simple as that. Let me know if i am off track here please. Thanks!

--- Edit

when the torrent is added to the system, last_activity = added time when the torrent is set to download complete, last activity = now() when the torrent is downloading, last_activity = now() when the torrent is uploading, last_activity = now()

when the torrent is paused, errored or any other status really, last_activity = last_activity (leave it alone as status changes have nothing to do with the last time the torrent was active in regards to upload/download)

--- Edit 2

If for whatever reason you want to consider internal changes (paused, move location, rename, etc) as activity that is fine too, last_activity = now() for those cases too (however i think that last_activity should be upload/download based personally)

FranciscoPombal commented 4 years ago

Yes, my initial suspicion is also that sometimes the value in question is supposed to be an absolute timestamps, other times a difference between the current time and some other timestamp.

I haven't looked at the code too carefully since then, but I would bet -1 is supposed to be . This is probably for some logic like if time_active > threshold then time_active = -1, which would be a cosmetic decision.

I agree that the value should always be an absolute timestamp, but I generally disagree with:

when the torrent is added to the system, last_activity = added time when the torrent is set to download complete, last activity = now() when the torrent is downloading, last_activity = now() when the torrent is uploading, last_activity = now()

when the torrent is paused, errored or any other status really, last_activity = last_activity (leave it alone as status changes have nothing to do with the last time the torrent was active in regards to upload/download)

IMO, it should be:

Additionally, should not be used.

austinwbest commented 4 years ago

Yes, with a timestamp that would eliminate the need for infinity completely.

austinwbest commented 4 years ago
    if (torrent.isPaused() || torrent.isChecking()) {
        ret[KEY_TORRENT_LAST_ACTIVITY_TIME] = 0;
    }
    else {
        const qint64 dt = (QDateTime::currentDateTime().toSecsSinceEpoch()
            - torrent.timeSinceActivity());
        ret[KEY_TORRENT_LAST_ACTIVITY_TIME] = dt;
    }

Would be removed and become a define like everything else

{KEY_TORRENT_LAST_ACTIVITY_TIME, (QDateTime::currentDateTime().toSecsSinceEpoch() - torrent.timeSinceActivity())},

Then anywhere that needs to do something with it (in the UI) would treat it as a timestamp. This seems so simple so i am very confused why it wasn't implmented this way, surely there was a reason that i dunno about since i am new to this project?

FranciscoPombal commented 4 years ago

@austinwbest have you tested that change for yourself and found that it works correctly in all cases? If so, I don't see a reason why it could not be that way.

Plus, the user interface does not necessarily have to display absolute timestamps - it can make a few calculations so that the user sees "n weeks ago" instead of "yyyy-mm-dd hh:mm:ss". This way it makes the most sense to me:

EDIT: A simple case-insensitive ctrl+f "last_activ" through the code base indicates changes to code in the transferlist*.cpp files might also be needed.

@glassez @Chocobo1 is there something we're missing here?

FranciscoPombal commented 4 years ago

Plus, is this still an issue? @arvidn

https://github.com/qbittorrent/qBittorrent/blob/8a8607bf93bb0bdc0ffa533847a96c762b0ed9f9/src/webui/api/synccontroller.cpp#L422

austinwbest commented 4 years ago

Yes, the UI would not necessarily use it as is. A function could be written if not already called dateDiff(start, end) for example that returns a 'pretty' output.

austinwbest commented 4 years ago

Plus, is this still an issue? @arvidn

https://github.com/qbittorrent/qBittorrent/blob/8a8607bf93bb0bdc0ffa533847a96c762b0ed9f9/src/webui/api/synccontroller.cpp#L422

I'd be completely fine with a 10 second discrepancy vs the situation it is currently in. I'd be all for removing every modification done to the last active time internally and only tweak the UI display of it. That being said i am kinda waiting for some of the others to reply that you tagged as i guess they have been around longer and could clarify some of the history here.