You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 653efdf
Browse filesBrowse the repository at this point in the historyBrowse files
* that have consecutive IDs and were created within <2 seconds.
9
+
* Detect and optionally delete duplicate event *chains* in 2025
10
+
* (same title, start_date, end_date) created within <2s of each other.
11
11
*
12
12
* Related pivot tables:
13
13
* - event_tag
@@ -27,74 +27,109 @@ class CleanDuplicateEvents extends Command
27
27
protected$signature = 'events:clean-duplicates {--delete : Permanently delete detected duplicates and related records from DB}';
28
28
29
29
/** @var string */
30
-
protected$description = 'Detect duplicate events (same title, start_date, end_date, consecutive IDs, created <2s apart) and optionally delete them with related pivot data.';
30
+
protected$description = 'Detect duplicate event groups in 2025 (same title/start/end, created <2s apart) and optionally delete them with related pivot data.';
31
31
32
32
publicfunctionhandle(): int
33
33
{
34
34
$shouldDelete = $this->option('delete');
35
35
36
36
$this->info(sprintf(
37
-
'Scanning for possible duplicate events... (mode: %s)',
37
+
'Scanning for possible duplicate events in 2025... (mode: %s)',
38
38
$shouldDelete ? 'DELETE' : 'DRY-RUN'
39
39
));
40
40
41
-
// --- Detect duplicate event pairs ---
41
+
// --- Detect clusters of events with same title/start/end within 2 seconds ---
42
42
$duplicates = DB::select("
43
43
SELECT
44
-
e1.id AS id1,
45
-
e2.id AS id2,
46
-
e1.title,
47
-
e1.start_date,
48
-
e1.end_date,
49
-
TIMESTAMPDIFF(SECOND, e1.created_at, e2.created_at) AS diff_seconds
50
-
FROM events e1
51
-
JOIN events e2 ON e2.id = e1.id + 1
52
-
WHERE e1.title = e2.title
53
-
AND e1.start_date = e2.start_date
54
-
AND e1.end_date = e2.end_date
55
-
AND ABS(TIMESTAMPDIFF(SECOND, e1.created_at, e2.created_at)) < 2
56
-
ORDER BY e1.id
44
+
e.id,
45
+
e.title,
46
+
e.start_date,
47
+
e.end_date,
48
+
e.created_at,
49
+
LAG(e.created_at) OVER (PARTITION BY e.title, e.start_date, e.end_date ORDER BY e.created_at) AS prev_created
0 commit comments