X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=blobdiff_plain;f=inc%2Flibs%2Fsurfbar_functions.php;h=1c676079a1b9bab66fa350ac92364f5836ca5a7b;hp=8d1df27d7976eb349f7ebb97ba80f830f9342d22;hb=c47293f5523a4a9e8791f0922b138fa6865aefaf;hpb=7f5d2604c2b0bfa6983ece1d58febabc5159d25a
diff --git a/inc/libs/surfbar_functions.php b/inc/libs/surfbar_functions.php
index 8d1df27d79..1c676079a1 100644
--- a/inc/libs/surfbar_functions.php
+++ b/inc/libs/surfbar_functions.php
@@ -416,8 +416,45 @@ function SURFBAR_GET_NEXT_ID ($id = 0) {
$randNum = mt_rand(0, $maxRand);
} // END - if
+ // Get all id from locks within the timestamp
+ $result = SQL_QUERY_ESC("SELECT id, url_id, UNIX_TIMESTAMP(last_surfed)
+FROM
+ "._MYSQL_PREFIX."_surfbar_locks
+WHERE
+ userid=%s
+ORDER BY
+ id ASC", array($GLOBALS['userid']),
+ __FILE__, __LINE__);
+
+ // Load all entries
+ $IDs = array(); $USE = array();
+ $ignored = array();
+ while (list($id, $url, $last) = SQL_FETCHROW($result)) {
+ //* DEBUG: */ echo __FUNCTION__.": next - id={$id},url={$url},last={$last}
\n";
+ // Skip entries that are too old
+ if (($last < (time() - SURFBAR_GET_DATA('surf_lock'))) && (!in_array($url, $ignored))) {
+ //* DEBUG: */ echo __FUNCTION__.": okay - id={$id},url={$url},last={$last}
\n";
+ // Add only if missing or bigger
+ if ((!isset($IDs[$url])) || ($IDs[$url] <= $last)) {
+ // Add this ID
+ //* DEBUG: */ echo __FUNCTION__.": ADD - id={$id},url={$url},last={$last}
\n";
+ $IDs[$url] = $last;
+ $USE[$url] = $id;
+ } // END - if
+ } else {
+ // Ignore these old entries!
+ //* DEBUG: */ echo __FUNCTION__.": ignore - id={$id},url={$url},last={$last}
\n";
+ $ignored[] = $url;
+ unset($IDs[$url]);
+ unset($USE[$url]);
+ }
+ } // END - if
+
+ // Free result
+ SQL_FREERESULT($result);
+
// And query the database
- //* DEBUG: */ echo __FUNCTION__.":randNum={$randNum},maxRand={$maxRand}
\n";
+ //* DEBUG: */ echo __FUNCTION__.":randNum={$randNum},maxRand={$maxRand},surfLock=".SURFBAR_GET_DATA('surf_lock')."
\n";
$result = SQL_QUERY_ESC("SELECT sbu.id, sbu.userid, sbu.url, sbs.last_salt, sbu.reward, sbu.costs, sbu.views_total, p.time, UNIX_TIMESTAMP(l.last_surfed) AS last_surfed
FROM "._MYSQL_PREFIX."_surfbar_urls AS sbu
LEFT JOIN "._MYSQL_PREFIX."_payments AS p
@@ -426,11 +463,18 @@ LEFT JOIN "._MYSQL_PREFIX."_surfbar_salts AS sbs
ON sbu.id=sbs.url_id
LEFT JOIN "._MYSQL_PREFIX."_surfbar_locks AS l
ON sbu.id=l.url_id
-WHERE sbu.userid != %s AND sbu.status='CONFIRMED' AND (l.last_surfed IS NULL OR (UNIX_TIMESTAMP() - ".SURFBAR_GET_DATA('surf_lock').") >= UNIX_TIMESTAMP(l.last_surfed))
+WHERE sbu.userid != %s AND sbu.status='CONFIRMED' AND l.id IN (".implode(",", $USE).")
+GROUP BY sbu.id
ORDER BY l.last_surfed ASC, sbu.id ASC
LIMIT %s,1",
array($GLOBALS['userid'], $randNum), __FILE__, __LINE__
);
+ /*
+ while($content = SQL_FETCHARRAY($result)) {
+ echo "
".print_r($content, true).""; + } + die(); + */ } else { // Get data from specified id number $result = SQL_QUERY_ESC("SELECT sbu.id, sbu.userid, sbu.url, sbs.last_salt, sbu.reward, sbu.costs, sbu.views_total, p.time, UNIX_TIMESTAMP(l.last_surfed) AS last_surfed @@ -450,9 +494,9 @@ LIMIT 1", // Is there an id number? if (SQL_NUMROWS($result) == 1) { // Load/cache data - //* DEBUG: */ echo __FUNCTION__.":".count($SURFBAR_CACHE)."*