MCPcopy Index your code
hub / github.com/syncthing/syncthing / needSizeRemote

Method needSizeRemote

internal/db/sqlite/folderdb_counts.go:79–106  ·  view source on GitHub ↗
(device protocol.DeviceID)

Source from the content-addressed store, hash-verified

77}
78
79func (s *folderDB) needSizeRemote(device protocol.DeviceID) (db.Counts, error) {
80 var res []countsRow
81 // See neededGlobalFilesRemote for commentary as that is the same query without summing
82 if err := s.stmt(`
83 SELECT g.type, count(*) as count, sum(g.size) as size, g.local_flags, g.deleted FROM files g
84 WHERE g.local_flags & {{.FlagLocalGlobal}} != 0 AND NOT g.deleted AND g.local_flags & {{.LocalInvalidFlags}} = 0 AND NOT EXISTS (
85 SELECT 1 FROM FILES f
86 INNER JOIN devices d ON d.idx = f.device_idx
87 WHERE f.name_idx = g.name_idx AND f.version_idx = g.version_idx AND d.device_id = ?
88 )
89 GROUP BY g.type, g.local_flags, g.deleted
90
91 UNION ALL
92
93 SELECT g.type, count(*) as count, sum(g.size) as size, g.local_flags, g.deleted FROM files g
94 WHERE g.local_flags & {{.FlagLocalGlobal}} != 0 AND g.deleted AND g.local_flags & {{.LocalInvalidFlags}} = 0 AND EXISTS (
95 SELECT 1 FROM FILES f
96 INNER JOIN devices d ON d.idx = f.device_idx
97 WHERE f.name_idx = g.name_idx AND d.device_id = ? AND NOT f.deleted AND f.local_flags & {{.LocalInvalidFlags}} = 0
98 )
99 GROUP BY g.type, g.local_flags, g.deleted
100 `).Select(&res, device.String(),
101 device.String()); err != nil {
102 return db.Counts{}, wrap(err)
103 }
104
105 return summarizeCounts(res), nil
106}
107
108func summarizeCounts(res []countsRow) db.Counts {
109 c := db.Counts{

Callers 1

CountNeedMethod · 0.95

Calls 5

summarizeCountsFunction · 0.85
stmtMethod · 0.80
wrapFunction · 0.70
SelectMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected