Commit graph

108 commits

Author SHA1 Message Date
Daimona Eaytoy
1d6776fdbc Replace deprecated MWException
Also remove some unchecked exception from doc comments.

Bug: T328220
Bug: T240672
Change-Id: I88b1e948ce5da77d9c4862a2b98793d6ba00cf8b
2024-01-19 21:58:42 +00:00
Timo Tijhof
937847b26a Replace various magic numbers with easy-to-verify expressions
Follows-up I8518e0488 (9c02258a04).

Instead of documenting how to compute the number to manually verify
it, use the expression directly. This should make it significantly
easier to understand, verify, and modify.

Noteworthy:

* Language.php, I kept 31_556_952 as-is because the
  calculation would otherwise involve a float. It also has the benefit
  of allowing the long durations to build upon that as a given number.

* SqlBlobStore.php, remove this irrelevant default value as it is
  unreachable. The only call to new SqlBlobStore is BlobStoreFactory,
  which always calls setCacheExpiry. For back-compat and to keep
  tests as-is, move to re-used constant between class and config.

Change-Id: I86b034883bd7efdf93b8365b43178af826f1c703
2024-01-11 15:12:24 +11:00
Tim Starling
9c02258a04 Use thousands separators in selected integer literals
For readability. Allowed since PHP 7.4.

I searched for integer literals of 6 or more digits, and also changed
some nearby smaller numbers for consistency.

Bug: T353205
Change-Id: I8518e04889ba8fd52e0f9476a74f8e3e1454b678
2023-12-12 09:22:45 +11:00
Amir Sarabadani
17589adcc4 Migrate another batch to use $db->expr instead of raw SQL
Bug: T210206
Change-Id: I327517fef250c24392565a26bbe7b296dc19508a
2023-10-30 17:56:35 -04:00
Bartosz Dziewoński
c9683b7092 Replace more single-value $db->buildComparison() with $db->expr()
A few more fairly simple cases that don't quite match the regexp in
I2cfc3070c2a08fc3888ad48a995f7d79198cc336 or required other tweaks.

Change-Id: I5438c777344e9ba07f3b62a452fce9ec63baa48a
2023-10-22 01:06:04 +02:00
Bartosz Dziewoński
978d739bc6 Replace single-value $db->buildComparison() with $db->expr()
Find:
->buildComparison\( ('..?'), \[(\s*)([^\],]+) => ([^\],]+)(\s*)\] \)

Replace with:
->expr($2$3, $1, $4$5)

Change-Id: I2cfc3070c2a08fc3888ad48a995f7d79198cc336
2023-10-22 01:05:47 +02:00
Tim Starling
95bd40b25c In query builders, use insertInto() and deleteFrom() instead of insert() and delete()
The design principle for SelectQueryBuilder was to make the chained
builder calls look as much like SQL as possible, so that developers
could leverage their knowledge of SQL to understand what the query
builder is doing.

That's why SelectQueryBuilder::select() takes a list of fields, and by
the same principle, it makes sense for UpdateQueryBuilder::update() to
take a table. However with "insert" and "delete", the SQL designers
chose to add prepositions "into" and "from", and I think it makes sense
to follow that here.

In terms of natural language, we update a table, but we don't delete a
table, or insert a table. We delete rows from a table, or insert rows
into a table. The table is not the object of the verb.

So, add insertInto() as an alias for insert(), and add deleteFrom() as
an alias for delete(). Use the new methods in MW core callers where
PHPStorm knows the type.

Change-Id: Idb327a54a57a0fb2288ea067472c1e9727016000
2023-09-08 10:16:08 +10:00
Amir Sarabadani
98d6503f65 Mass migrate Database::insert calls to InsertQueryBuilder
Done automatically based on a php parser written on top of ANTLR4

Bug: T335377
Change-Id: Ie8fabc594edab18e55cb1d5bbf573762106e3d71
2023-08-07 19:44:27 +02:00
Amir Sarabadani
b57b81066e rdbms: Remove or move unused public methods of ILB/ILBF
These methods are either:
 - Completely unused, removed
 - Used only by the class itself, made private
 - Used by LBF (ILB methods) which they were moved to
   ILoadBalancerForOwner

In the meantime, completely deprecating and removing per-domain and
per-cluster waitForReplication. Simply wait for all LBs to catch up:
 * In reality, the replication lag is so small that it doesn't matter.
   It's probably caught up already by that point anyway.
 * If you don't make a db call, you don't init a new LBF to be waited on
   so it's already quite small.

Bug: T326274
Change-Id: I2c0a89d70152de56d35290f2666b6699822ed330
2023-08-01 10:33:43 +00:00
Umherirrender
fe40101587 Replace IDatabase::delete with DeleteQueryBuilder
Change-Id: Ie0c1c955ca1a7028f75f24563fdeb9f94285af30
2023-06-21 17:50:31 +02:00
Alexander Vorwerk
d93c9001f4 Migrate more usages of Database::update() to UpdateQueryBuilder
Bug: T330640
Change-Id: I094eea810886b13d832be575d9b9df8f8e4a77ea
2023-06-09 13:36:04 +00:00
Amir Sarabadani
b55c501fe0 Migrate Database::update() to UpdateQueryBuilder
I did this using a script written on top of antlr4 parser so it doesn't
have some clean ups a human would do but it's pretty nice already.

Bug: T330640
Change-Id: I608566700c6d737ee986bf47dda87effc69614d6
2023-06-08 12:34:20 +02:00
Amir Sarabadani
7ffd35ecc6 rdbms: Remove Database::attributesFromType and hard-deprecate ::factory
They have been soft-deprecated since 1.39 and the first one is not used
anywhere, ::factory is used in some third party code but not in
Wikimedia-deployed ones

Change-Id: Icd0f743d9c76554dd02471485ee732e25b9fb932
2023-02-23 17:59:54 +00:00
Amir Sarabadani
a4f296facf jobqueue: Migrate all IDatabase::select to SelectQueryBuilder
And some clean ups while we are at it like using buildComparison instead
of raw SQL.

Bug: T311866
Change-Id: Ib1bc73a2987763fcad667d393138a64c529f53d1
2023-02-23 15:01:57 +00:00
jenkins-bot
0d1dc069f6 Merge "jobqueue: Add documentation about specific type to Iterator type" 2023-02-16 21:55:32 +00:00
Adam Wight
5ea23a5b6e Document exceptions
Some of these can probably be removed.  In the meantime, documenting
makes it easier to understand their purpose.

Change-Id: I5bc407f56ce4eb915c7a3f2868fe66675769f723
2022-11-28 17:04:25 +00:00
Matěj Suchánek
a90a065586 Remove deprecated getMasterDB methods
They have been deprecated since 1.37 and are unused.

Change-Id: I626525eead68e3ba50564ac629a86c7c8dc9dd73
2022-11-17 14:30:47 +01:00
Umherirrender
3a7bcb9c77 jobqueue: Add documentation about specific type to Iterator type
In manageJobs.php check for Job class to skip the check for RunnableJob
interface, which does not implement the method

Change-Id: I2a42bfc78140310cf3df9c882ffb089719af5466
2022-11-14 19:51:17 +01:00
Umherirrender
1b342a8893 Various doc fixes about false and null on method arguments/return types
Doc-only changes

Change-Id: Ice974b3ba41708859dfe646e94b31c5ebbf26410
2022-11-03 18:55:47 +01:00
Umherirrender
b9a5d69d26 JobQueueDB: Always use IDatabase::addQuotes for quoting
Use addQuotes to quote the empty string instead of hard-coding '',
for better rdbms support and is always used in the file

Change-Id: I92d6481b725ccf27da187196c2cc7feb423cf828
2022-07-09 23:47:54 +02:00
Umherirrender
25188a6ae8 jobqueue: JobQueueDB::jobFromRow cannot return null
Found by phan strict checks

Change-Id: Ic7b2b8d262b8cdb5954222944e0d5a8613d6123d
2022-02-26 08:16:03 +00:00
Siddharth VP
60faebb725 Fix typos in comments (I-J)
Change-Id: Icaea2b6665cfc3b811d94f70c93452237f5e72bf
2021-12-30 20:38:04 +05:30
James D. Forrester
86f3270bda Tag various new 'primary' methods as @since 1.37
Change-Id: Icbbbc84154174da1bd9398990679857898f418d5
2021-09-02 11:58:19 -07:00
Thiemo Kreuz
46f26dff03 Same code style and formatting for exists-style SQL queries
Queries that query a value "1" are expected to return either
that "1" (possibly as a string), or false. It's safe to simply
cast this to bool and use it as it is.

Queries for COUNT(*) are expected to return that number,
possibly as a string. It's not possible for such a query to
return false. And even if, casting to 0 is fine.

I found an existing code style where the table name and the
"1" are on the same line as the selectField() method name, and
applied it to all similar queries.

Change-Id: I9453196281871c03ef03f653f43762eb9284342f
2021-08-12 11:37:58 +02:00
James D. Forrester
9fe4138f3d Follow-up I68198bc3: Hard-deprecate getMasterDB() methods
Also switch one use that we missed in the rebase.

Bug: T254646
Depends-On: I632610dec1aa6bb59af5423e6f86164fc791aadd
Change-Id: I9873c889f943fcbd7d867d534a7857f20ef0c5dc
2021-07-15 09:12:17 +01:00
James D. Forrester
597376e12c Replace getMasterDB methods with getPrimaryDB
Bug: T254646
Change-Id: I68198bc39b174ea1920b4acc2617cb6c6ce406e9
2021-07-14 16:21:04 -07:00
James D. Forrester
f2f9345e39 Replace uses of DB_MASTER with DB_PRIMARY in documentation and local variables
This is just a start.

Bug: T254646
Change-Id: I9213aad4660e27afe7ff9e5d2e730cbf03911068
2021-05-14 12:40:34 -07:00
James D. Forrester
df5eb22f83 Replace uses of DB_MASTER with DB_PRIMARY
Just an auto-replace from codesniffer for now.

Change-Id: I5240dc9ac5929d291b0ef1c743ea2bfd3f428266
2021-04-29 09:24:31 -07:00
Reedy
4c2d7e87b8 JobQueueDB: Remove unused getReplicaDB() call
Change-Id: I9e33fee718281a63d0271ad8b898ee893b10b7c2
2021-04-21 14:43:17 +01:00
Sébastien Beyou
dec13460ea Implement JobQueueDB::getAllAbandonedJobs
Bug: T276945
Change-Id: I918356733409dd69ac438b0311ad7120d0b37d40
2021-04-05 21:53:22 +02:00
Umherirrender
8de3b7d324 Use static closures where safe to use
This is micro-optimization of closure code to avoid binding the closure
to $this where it is not needed.

Created by I25a17fb22b6b669e817317a0f45051ae9c608208

Change-Id: I0ffc6200f6c6693d78a3151cb8cea7dce7c21653
2021-02-11 00:13:52 +00:00
Umherirrender
a5ccb3e549 Avoid hard coded AS for column aliases
Use 'alias' => 'column' feature of the abstract database layer

Wikipage old code:
SELECT cl_to AS page_title, 14 AS page_namespace FROM `categorylinks`
WHERE cl_from = 651

Wikipage new code:
SELECT cl_to AS `page_title`,14 AS `page_namespace` FROM `categorylinks`
WHERE cl_from = 651

Change-Id: Ibd2fb22bd556f331b955378eb144153f2fdb9dc6
2020-09-21 21:07:14 +02:00
Thiemo Kreuz
9c6473dc1d Reduce nesting by turning big if-else into guard clauses
Change-Id: If3d2f18af0cc7d0f8fe9f764bd4d0e4bae70e440
2020-07-24 11:55:31 +02:00
Umherirrender
fd1ed0c092 Pass function name to database functions
Useful for logging

Change-Id: Ia2160fb6be5fc93f28ab51f7ae23d7f078247481
2020-06-07 14:16:52 +02:00
Tim Starling
47a1619027 Remove terminating line breaks from debug messages
A terminating line break has not been required in wfDebug() since 2014,
however no migration was done. Some of these line breaks found their way
into LoggerInterface::debug() calls, where they mess up the formatting
of the debug log.

So, remove terminating line breaks from wfDebug() and
LoggerInterface::debug() calls.

Also:
* Fix the stripping of leading line breaks from the log header emitted
  by Setup.php. This feature, accidentally broken in 2014, allows
  requests to be distinguished in the log file.
* Avoid using the global variable $self.
* Move the logging of the client IP back to Setup.php. It was moved to
  WebRequest in the hopes that it would not always be needed, however
  $wgRequest->getIP() is now called unconditionally a few lines up in
  Setup.php. This means that it is put in its proper place after the
  "start request" message.
* Wrap the log header code in a closure so that variables like $name do
  not leak into global scope.
* In Linker.php, remove a few instances of an unnecessary second
  parameter to wfDebug().

Change-Id: I96651d3044a95b9d210b51cb8368edc76bebbb9e
2020-06-03 12:01:16 +10:00
Reedy
d53e91d272 Fix more PSR12.Properties.ConstantVisibility.NotFound
Change-Id: I94520b10d78a17ea8e965633dd475ea711f25c99
2020-05-15 00:33:32 +01:00
James D. Forrester
4f2d1efdda Coding style: Auto-fix MediaWiki.Classes.UnsortedUseStatements.UnsortedUse
Change-Id: I94a0ae83c65e8ee419bbd1ae1e86ab21ed4d8210
2020-01-10 09:32:25 -08:00
Brad Jorsch
b26248235b Add string casts when using array_keys() with SQL query conditions
Until I70473280, integer literals were always quoted as strings, because
the databases we support all have no problem with casting
string-literals for comparisons and such.

But it turned out that gave MySQL/MariaDB's planner problems in some
queries, so we changed it to not quote actual PHP integers.

But then we run into the fact that PHP associative arrays don't preserve
the types of keys, it converts integer-like strings into actual
integers. And when those are passed to the DB unquoted for comparison
with a string-typed column, MySQL/MariaDB screws up the comparison while
PostgreSQL simply throws an error. Sigh.

This patch adds string casting to direct uses of array_keys() to supply
values for such query conditions. It doesn't change uses where the field
being compared is a numeric field.

If anyone knows of a good way to find indirect uses of array_keys() for
passing as $conds to IDatabase methods, please do so!

Change-Id: Ie72ee33437d492904e1495b3f4ebb1fcf0118f49
2019-12-16 16:05:18 -05:00
Daimona Eaytoy
f18af0b61f Remove more Oracle and Mssql leftovers
Follows-up 4d10bb14e8 and 807d793ab9.

According to codesearch [0], these were the last usages. Note that this
patch leaves two constants in places, IDatabase::DBO_SYSDBA and
DBO_DDLMODE. These are public constants used "mostly for oracle" according
to the docs, but maybe we could find other use cases in the future (?).

[0] - https://codesearch.wmflabs.org/core/?q=oracle%7Cmssql&i=fosho&files=%5C.%5B%5Ej%5Cd%5D%7Cen%5C.json&repos=

Bug: T230418
Change-Id: Ibfb748b4b23b885a77f4de161af4bf2ab9649a89
2019-08-25 17:21:49 +00:00
Aaron Schulz
97cbaa349e Cleanup JobQueueDB::recycleAndDeleteStaleJobs() use of IDatabase::affectedRows()
Bug: T229456
Change-Id: Ie22085ddba66f122e59e93baaf9b53c76b5ce448
2019-08-08 10:59:26 +00:00
Aaron Schulz
43c78e83d7 jobqueue: migrate root job deduplication to the WAN cache
If the root job timestamp keys are lost or otherwise unknown, they
will now be deductively recached with the best known values as jobs
are popped and executed. This means the running any of many child
jobs of a root job can restore the root timestamp if it was lost.
This does not need to use the main stash given this fact.

Bug: T227376
Change-Id: Iae0f3af15803af048ff49f3bf281b2bde18c87f2
2019-07-13 15:38:17 -07:00
Aaron Schulz
aa4f4d6b53 jobqueue: make JobQueueDB stricter about broken job_params fields
Also rename throwDBException() to getDBException() and make the
callers throw the result to avoid phpstorm warnings. Remove $row
assignment that is always overridden as well.

Change-Id: I84bc4b11f10152eada6dd6f4788c4f79dcb4a2fb
2019-04-27 00:14:12 +00:00
Aaron Schulz
fc5d51f129 jobqueue: add GenericParameterJob and RunnableJob interface
Simplify the code of jobs that do not care about titles and removes
the direct Title dependency from JobQueue. Remove getTitle() from
IJobSpecification itself. Move all the Job::factory calls into a
single JobQueue::factoryJob() method.

Depends-on: Iee78f4baeca0c0b4d6db073f2fbcc56855114ab0
Change-Id: I9c9d0726d4066bb0aa937665847ad6042ade13ec
2019-04-08 11:05:23 -07:00
Aaron Schulz
b48dcf28d6 jobqueue: dependency inject more objects into JobQueue
Also moved some WikiMap/$wgJobClasses checks to JobQueueGroup::pop
which is the method callers are supposed to use.

Change-Id: I2ab82d8adc4ae1f54697d2935afa2053539cf2db
2019-04-04 01:32:59 -07:00
jenkins-bot
a0f9d54f11 Merge "Add Job::getMetadata() and Job::setMetadata() accessors" 2019-04-03 17:43:40 +00:00
jenkins-bot
f28f7a0d0f Merge "jobqueue: remove entire unused JobQueueAggregator class hierarchy" 2019-04-03 17:43:31 +00:00
Aaron Schulz
a51ea350be Add Job::getMetadata() and Job::setMetadata() accessors
Change-Id: I3a97008d324f600a1c9f6005673073277ee564fa
2019-04-03 16:34:32 +00:00
Aaron Schulz
4122e53845 jobqueue: fix DBO_TRX logic in JobQueueDB for avoiding transactions
Various methods were missing the flag setting logic and tests could
fail or have "outer scope" warnings in the logs for sqlite.

Change-Id: Ia0607d189a307667297f06109a34363c92e37d92
2019-04-01 22:29:31 +00:00
Aaron Schulz
196ef348c5 jobqueue: remove entire unused JobQueueAggregator class hierarchy
Change-Id: I3d56d5db54fcb4278c7cf2a8d08933c27773c3f7
2019-03-29 20:25:05 -07:00
Aaron Schulz
236e6ae11e jobqueue: allow direct server configuration arrays to JobQueueDB
This is useful for using a separate sqlite DB.

Change-Id: I6a7bb1d4bddedca34d68b0d8460c96c6ef5bbcf6
2019-03-09 03:40:20 +00:00