@@ -66,12 +66,49 @@ public void update(String sql) {
6666 }
6767 }
6868
69+ /////////////////////////////////////////////////////////////////////////////////////////
70+ /////////////////////////////////////////////////////////////////////////////////////////
71+
72+ public void updateLastUrlCheck (List <Film > checked ) {
73+ try {
74+ AtomicInteger updateCounter = new AtomicInteger (0 );
75+ List <Future <?>> futures = new ArrayList <>();
76+ List <Film > allVideos = checked .stream ()
77+ .sorted (Comparator .comparing (Film ::getId ))
78+ .toList ();
79+ for (int i = 0 ; i < allVideos .size (); i += batchSize ) {
80+ int from = i ;
81+ int to = Math .min (i + batchSize , allVideos .size ());
82+ List <Film > batch = allVideos .subList (from , to );
83+ futures .add (executorService .submit (() -> {
84+ String sql = "UPDATE filme SET last_url_check = NOW() WHERE id = ?" ;
85+ try (Connection con = dataSource .getConnection (); PreparedStatement ps = con .prepareStatement (sql )) {
86+ for (Film video : batch ) {
87+ ps .setString (1 , video .getId ());
88+ ps .addBatch ();
89+ }
90+ int [] rs = ps .executeBatch ();
91+ for (int rsCode : rs ) {
92+ updateCounter .addAndGet (rsCode );
93+ }
94+ } catch (SQLException e ) {
95+ LOG .error (e );
96+ }
97+ }));
98+ }
99+ futures .forEach ( f -> {try { f .get (); } catch (Exception e ) { LOG .error ("{}" ,e ); }});
100+ LOG .debug ("updated lastUrlCheck {}" , updateCounter .get ());
101+ } catch (Exception e ) {
102+ LOG .error (e );
103+ }
104+ }
105+
69106 /////////////////////////////////////////////////////////////////////////////////////////
70107 /////////////////////////////////////////////////////////////////////////////////////////
71108
72109 public void deleteFilms (Collection <Film > abandonedFilmlist ) {
73110 try {
74- List <Future <List < Film > >> futures = new ArrayList <>();
111+ List <Future <? >> futures = new ArrayList <>();
75112 List <Film > allVideos = abandonedFilmlist .stream ()
76113 .sorted (Comparator .comparing (Film ::getId ))
77114 .toList ();
@@ -80,7 +117,6 @@ public void deleteFilms(Collection<Film> abandonedFilmlist) {
80117 int to = Math .min (i + batchSize , allVideos .size ());
81118 List <Film > batch = allVideos .subList (from , to );
82119 futures .add (executorService .submit (() -> {
83- List <Film > newVideos = new ArrayList <>();
84120 String sql = "DELETE FROM filme WHERE id = ?" ;
85121 try (Connection con = dataSource .getConnection (); PreparedStatement ps = con .prepareStatement (sql )) {
86122 for (Film video : batch ) {
@@ -91,13 +127,9 @@ public void deleteFilms(Collection<Film> abandonedFilmlist) {
91127 } catch (SQLException e ) {
92128 LOG .error (e );
93129 }
94- return newVideos ;
95130 }));
96131 }
97- List <Film > result = new ArrayList <>();
98- for (Future <List <Film >> f : futures ) {
99- result .addAll (f .get ());
100- }
132+ futures .forEach ( f -> {try { f .get (); } catch (Exception e ) { LOG .error ("{}" ,e ); }});
101133 LOG .debug ("deleted {}" , abandonedFilmlist .size ());
102134
103135 } catch (Exception e ) {
@@ -157,13 +189,10 @@ public <T> List<T> filterNewVideos(Sender sender, List<T> videos, Function<T, St
157189 List <T > newVideos = new ArrayList <>();
158190 StringBuffer sql = new StringBuffer ();
159191 sql .append ("UPDATE filme SET last_seen = now() " )
160- .append ("WHERE id = ? AND (" )
161- .append ("( cast(created_at as date) = cast(last_update as date) and cast(created_at as date) <> cast(now() as date) )" )
162- .append (" OR " )
163- .append ("(last_seen - last_update <= interval '" ).append (refreshIntervalInDays ).append ("' DAY)" )
164- .append (")" );
192+ .append ("WHERE id = ? " )
193+ .append ("AND NOT( created_at::date = last_update::date and last_update::date <> CURRENT_DATE ) " )
194+ .append ("AND NOT( last_seen - last_update >= interval '" ).append (refreshIntervalInDays ).append ("' DAY)" );
165195 try (Connection con = dataSource .getConnection (); PreparedStatement ps = con .prepareStatement (sql .toString ())) {
166-
167196 for (T video : batch ) {
168197 String id = idExtractor .apply (video );
169198 if (id != null ) {
0 commit comments