Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
2b2ae4ee
Kaydet (Commit)
2b2ae4ee
authored
Ara 25, 2018
tarafından
Simon Charette
Kaydeden (comit)
Tim Graham
Ara 26, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Refs #30054, #20483 -- Cached SQLite references graph retrieval on sql_flush().
üst
7a6dbbb6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
18 deletions
+29
-18
operations.py
django/db/backends/sqlite3/operations.py
+29
-18
No files found.
django/db/backends/sqlite3/operations.py
Dosyayı görüntüle @
2b2ae4ee
import
datetime
import
decimal
import
uuid
from
functools
import
lru_cache
from
itertools
import
chain
from
django.conf
import
settings
from
django.core.exceptions
import
FieldError
...
...
@@ -11,6 +13,7 @@ from django.db.models.expressions import Col
from
django.utils
import
timezone
from
django.utils.dateparse
import
parse_date
,
parse_datetime
,
parse_time
from
django.utils.duration
import
duration_microseconds
from
django.utils.functional
import
cached_property
class
DatabaseOperations
(
BaseDatabaseOperations
):
...
...
@@ -158,28 +161,36 @@ class DatabaseOperations(BaseDatabaseOperations):
def
no_limit_value
(
self
):
return
-
1
def
__references_graph
(
self
,
table_name
):
query
=
"""
WITH tables AS (
SELECT
%
s name
UNION
SELECT sqlite_master.name
FROM sqlite_master
JOIN tables ON (sql REGEXP
%
s || tables.name ||
%
s)
) SELECT name FROM tables;
"""
params
=
(
table_name
,
r'(?i)\s+references\s+("|\')?'
,
r'("|\')?\s*\('
,
)
with
self
.
connection
.
cursor
()
as
cursor
:
results
=
cursor
.
execute
(
query
,
params
)
return
[
row
[
0
]
for
row
in
results
.
fetchall
()]
@cached_property
def
_references_graph
(
self
):
# 512 is large enough to fit the ~330 tables (as of this writing) in
# Django's test suite.
return
lru_cache
(
maxsize
=
512
)(
self
.
__references_graph
)
def
sql_flush
(
self
,
style
,
tables
,
sequences
,
allow_cascade
=
False
):
if
tables
and
allow_cascade
:
# Simulate TRUNCATE CASCADE by recursively collecting the tables
# referencing the tables to be flushed.
query
=
"""
WITH tables AS (
%
s
UNION
SELECT sqlite_master.name
FROM sqlite_master
JOIN tables ON (
sql REGEXP
%%
s || tables.name ||
%%
s
)
) SELECT name FROM tables;
"""
%
' UNION '
.
join
(
"SELECT '
%
s' name"
%
table
for
table
in
tables
)
params
=
(
r'(?i)\s+references\s+("|\')?'
,
r'("|\')?\s*\('
,
)
with
self
.
connection
.
cursor
()
as
cursor
:
results
=
cursor
.
execute
(
query
,
params
)
tables
=
[
row
[
0
]
for
row
in
results
.
fetchall
()]
tables
=
set
(
chain
.
from_iterable
(
self
.
_references_graph
(
table
)
for
table
in
tables
))
sql
=
[
'
%
s
%
s
%
s;'
%
(
style
.
SQL_KEYWORD
(
'DELETE'
),
style
.
SQL_KEYWORD
(
'FROM'
),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment