]> git.mxchange.org Git - friendica.git/blob - include/queue_fn.php
don't make -desc so obnoxious looking
[friendica.git] / include / queue_fn.php
1 <?php
2
3 function update_queue_time($id) {
4         logger('queue: requeue item ' . $id);
5         q("UPDATE `queue` SET `last` = '%s' WHERE `id` = %d LIMIT 1",
6                 dbesc(datetime_convert()),
7                 intval($id)
8         );
9 }
10
11 function remove_queue_item($id) {
12         logger('queue: remove queue item ' . $id);
13         q("DELETE FROM `queue` WHERE `id` = %d LIMIT 1",
14                 intval($id)
15         );
16 }
17
18 function was_recently_delayed($cid) {
19
20         $r = q("SELECT `id` FROM `queue` WHERE `cid` = %d 
21                 and last > UTC_TIMESTAMP() - interval 15 minute limit 1",
22                 intval($cid)
23         );
24         if(count($r))
25                 return true;
26         return false;
27 }
28
29
30 function add_to_queue($cid,$network,$msg,$batch = false) {
31
32         $max_queue = get_config('system','max_contact_queue');
33         if($max_queue < 1)
34                 $max_queue = 500;
35
36         $batch_queue = get_config('system','max_batch_queue');
37         if($batch_queue < 1)
38                 $batch_queue = 1000;
39
40         $r = q("SELECT COUNT(*) AS `total` FROM `queue` left join `contact` ON `queue`.`cid` = `contact`.`id` 
41                 WHERE `queue`.`cid` = %d AND `contact`.`self` = 0 ",
42                 intval($cid)
43         );
44         if($r && count($r)) {
45                 if($batch &&  ($r[0]['total'] > $batch_queue)) {
46                         logger('add_to_queue: too many queued items for batch server ' . $cid . ' - discarding message');
47                         return;
48                 }
49                 elseif((! $batch) && ($r[0]['total'] > $max_queue)) {
50                         logger('add_to_queue: too many queued items for contact ' . $cid . ' - discarding message');
51                         return;
52                 }
53         }
54
55         q("INSERT INTO `queue` ( `cid`, `network`, `created`, `last`, `content`, `batch`)
56                 VALUES ( %d, '%s', '%s', '%s', '%s', %d) ",
57                 intval($cid),
58                 dbesc($network),
59                 dbesc(datetime_convert()),
60                 dbesc(datetime_convert()),
61                 dbesc($msg),
62                 intval(($batch) ? 1: 0)
63         );
64
65 }